Skip to content

Instantly share code, notes, and snippets.

@tim-br
Created February 19, 2026 20:12
Show Gist options
  • Select an option

  • Save tim-br/1633b9b972c568e85878703a8850ff97 to your computer and use it in GitHub Desktop.

Select an option

Save tim-br/1633b9b972c568e85878703a8850ff97 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# coding: utf-8
# In[25]:
from sklearn.datasets import load_iris
import pandas as pd
iris = load_iris()
iris.data.shape[1]
# In[21]:
iris.target.size
# In[27]:
df = pd.DataFrame(iris.data, columns=iris.feature_names)
df["target"] = iris.target
df
# In[31]:
df.plot(kind="scatter", x="petal length (cm)", y="target",grid=True)
# In[67]:
from sklearn.model_selection import train_test_split
targets = df["target"]
new_df = df.drop(["target"], axis=1)
X_train, X_test, y_train, y_test = train_test_split(new_df, targets, test_size=0.3, random_state=42)
X_train.iloc[50], y_train.iloc[50]
iris
from sklearn.tree import DecisionTreeClassifier
clf = DecisionTreeClassifier()
clf.fit(X_train, y_train)
prediction_results = clf.predict(X_test)
# In[70]:
import numpy as np
np.array_equal(prediction_results, y_test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment