ModuleNotFoundError

I have create this code which uses Scikit-Learn to train a simple machine learning model-

from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score

# Load the iris dataset
iris = datasets.load_iris()
X, y = iris.data, iris.target

# Split the dataset into a training and test set
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

# Train a decision tree classifier
clf = DecisionTreeClassifier()
clf.fit(X_train, y_train)

# Make predictions
y_pred = clf.predict(X_test)

# Calculate accuracy
accuracy = accuracy_score(y_test, y_pred)
print("Accuracy:", accuracy)

In this code- it’s showing an error ModuleNotFoundError: No module named ‘sklearn’

Any solution?

UPDATED- I found this resource but as per this Python course online content, I am able to resolve the above error but it’s not showing any results.

Thanks

Have you installed the module with pip? If not then it’s not going to be found.

1 Like