Iris - Regression - Jupyter Notebook
Iris - Regression - Jupyter Notebook
Iris - Regression - Jupyter Notebook
In [3]: df = pd.read_csv('Iris.csv')
df.head()
localhost:8888/notebooks/Iris_regression.ipynb 1/5
3/21/24, 5:20 PM Iris_regression - Jupyter Notebook
localhost:8888/notebooks/Iris_regression.ipynb 2/5
3/21/24, 5:20 PM Iris_regression - Jupyter Notebook
In [14]:
import mpl_toolkits.mplot3d
from sklearn.decomposition import PCA
fig = plt.figure(1, figsize=(8, 6))
ax = fig.add_subplot(111, projection="3d", elev=-150, azim=110)
X_reduced = PCA(n_components=3).fit_transform(iris.data)
ax.scatter(
X_reduced[:, 0],
X_reduced[:, 1],
X_reduced[:, 2],
c=iris.target,
s=40,
)
ax.set_title("First three PCA dimensions")
ax.set_xlabel("1st Eigenvector")
ax.xaxis.set_ticklabels([])
ax.set_ylabel("2nd Eigenvector")
ax.yaxis.set_ticklabels([])
ax.set_zlabel("3rd Eigenvector")
ax.zaxis.set_ticklabels([])
plt.show()
localhost:8888/notebooks/Iris_regression.ipynb 3/5
3/21/24, 5:20 PM Iris_regression - Jupyter Notebook
In [27]: X = iris.data
y = iris.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.6
# Create a classification model (here, Gaussian Naive Bayes)
model = GaussianNB()
# Train the model on the training data
model.fit(X_train, y_train)
# Use the trained model to make predictions on the test data
y_pred = model.predict(X_test)
# Evaluate the accuracy of the model
accuracy = accuracy_score(y_test, y_pred)
# Print the accuracy
print(f"Accuracy of the model: {accuracy:.2f}")
In [ ]:
In [ ]:
localhost:8888/notebooks/Iris_regression.ipynb 4/5
3/21/24, 5:20 PM Iris_regression - Jupyter Notebook
localhost:8888/notebooks/Iris_regression.ipynb 5/5