Download the sample files from the banner, then click Add files in the workbench. read_csv looks in /uploads.
Goal
List /uploads, fit a classifier on kiosk.csv, and cluster points.csv.
See what is attached
import os
print("uploads:", os.listdir("/uploads"))If that list is empty, attach the files and run again.
Kiosk classifier
import os
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
print("uploads:", os.listdir("/uploads"))
df = pd.read_csv("kiosk.csv")
print(df.head())
print(df["high"].value_counts())
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))city and product are text — skip them until you encode (Encode chapter) or use the Practice pipeline.
Cluster points
from sklearn.cluster import KMeans
pts = pd.read_csv("points.csv")
print(pts.head())
X = pts[["x", "y"]].to_numpy()
km = KMeans(n_clusters=3, n_init=10, random_state=0)
labels = km.fit_predict(X)
print("counts", np.bincount(labels))
plt.scatter(X[:, 0], X[:, 1], c=labels, alpha=0.75)
plt.scatter(
km.cluster_centers_[:, 0],
km.cluster_centers_[:, 1],
marker="x",
s=90,
c="black",
)
plt.title("points.csv")
plt.show()Pitfall
FileNotFoundError means the workbench cannot see the file in /uploads. Download from the banner, then Add files. Do not use fetch_openml.