Attach all three sample files (kiosk.csv, sales.csv, points.csv) with Add files. Paste each block as the whole editor — later blocks repeat the load so they still run alone.
high is 1 when that kiosk row looks like a high-revenue sale.
Goal
Build a pipeline on kiosk.csv, print metrics, plot the confusion matrix, and export predictions plus the model.
1. Load
import os
print("uploads:", os.listdir("/uploads"))
df = pd.read_csv("kiosk.csv")
print(df.head())
print(df["high"].value_counts())
print(df.dtypes)2. Numeric-only baseline
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
df = pd.read_csv("kiosk.csv")
X = df[["units", "price", "weekend"]]
y = df["high"]
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.3, random_state=0, stratify=y
)
clf = LogisticRegression(max_iter=200)
clf.fit(X_train, y_train)
print("accuracy:", round(accuracy_score(y_test, clf.predict(X_test)), 3))3. Pipeline with city and product
from sklearn.model_selection import train_test_split
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder, StandardScaler
from sklearn.pipeline import Pipeline
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, classification_report
df = pd.read_csv("kiosk.csv")
y = df["high"]
X = df.drop(columns=["high"])
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.3, random_state=0, stratify=y
)
prep = ColumnTransformer(
[
(
"cat",
OneHotEncoder(sparse_output=False, handle_unknown="ignore"),
["city", "product"],
),
("num", StandardScaler(), ["units", "price", "weekend"]),
]
)
pipe = Pipeline(
[
("prep", prep),
("clf", LogisticRegression(max_iter=200)),
]
)
pipe.fit(X_train, y_train)
pred = pipe.predict(X_test)
print("accuracy:", round(accuracy_score(y_test, pred), 3))
print(classification_report(y_test, pred, digits=3))4. Confusion matrix
from sklearn.model_selection import train_test_split
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder, StandardScaler
from sklearn.pipeline import Pipeline
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import confusion_matrix
df = pd.read_csv("kiosk.csv")
y = df["high"]
X = df.drop(columns=["high"])
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.3, random_state=0, stratify=y
)
pipe = Pipeline(
[
(
"prep",
ColumnTransformer(
[
(
"cat",
OneHotEncoder(sparse_output=False, handle_unknown="ignore"),
["city", "product"],
),
("num", StandardScaler(), ["units", "price", "weekend"]),
]
),
),
("clf", LogisticRegression(max_iter=200)),
]
)
pipe.fit(X_train, y_train)
cm = confusion_matrix(y_test, pipe.predict(X_test))
print(cm)
fig, ax = plt.subplots()
image = ax.imshow(cm, cmap="Blues")
fig.colorbar(image, ax=ax)
ax.set_xlabel("predicted")
ax.set_ylabel("true")
for i in range(2):
for j in range(2):
ax.text(j, i, str(cm[i, j]), ha="center", va="center")
ax.set_title("Kiosk high-revenue")
plt.show()5. Export
import os
import joblib
from sklearn.model_selection import train_test_split
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder, StandardScaler
from sklearn.pipeline import Pipeline
from sklearn.linear_model import LogisticRegression
df = pd.read_csv("kiosk.csv")
y = df["high"]
X = df.drop(columns=["high"])
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.3, random_state=0, stratify=y
)
pipe = Pipeline(
[
(
"prep",
ColumnTransformer(
[
(
"cat",
OneHotEncoder(sparse_output=False, handle_unknown="ignore"),
["city", "product"],
),
("num", StandardScaler(), ["units", "price", "weekend"]),
]
),
),
("clf", LogisticRegression(max_iter=200)),
]
)
pipe.fit(X_train, y_train)
pred = pipe.predict(X_test)
out = X_test.copy()
out["true"] = y_test.to_numpy()
out["pred"] = pred
out.to_csv("kiosk_pred.csv", index=False)
joblib.dump(pipe, "kiosk_pipe.joblib")
print("uploads:", os.listdir("/uploads"))
print(out.head())Click ↓ on kiosk_pred.csv and kiosk_pipe.joblib.
Extra drills
- Swap in
RandomForestClassifier(n_estimators=40, random_state=0, n_jobs=1). - Cluster
points.csvwithk=3and saveclusters.png. - Predict
revenueonsales.csvwithLinearRegression(nohighcolumn there).
You should see
If a CSV is missing, attach the banner files and run again. Empty Plot panel usually means the script never called plt.show().