ModuleNotFoundError: No module named 'sklearn.linear_model'; 'sklearn' is not a package
See original GitHub issueHi, I have already install sklearn package on my computer and i’ve also checked using cmd. Everything checkout fine, like its installed and its in the directory as well.
But i cant seem to import it in my pycharm
Code:
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import train_test_split
X = np.arange(100).reshape(100, 1)
y = X**4 + X**3 + X + 1
x_train, x_test, y_train, y_test = train_test_split(X, y, test_size=0.3)
rmses = []
degrees = np.arange(1, 10)
min_rmse, min_deg = 1e10, 0
for deg in degrees:
# Train features
poly_features = PolynomialFeatures(degree=deg, include_bias=False)
x_poly_train = poly_features.fit_transform(x_train)
# Linear regression
poly_reg = LinearRegression()
poly_reg.fit(x_poly_train, y_train)
# Compare with test data
x_poly_test = poly_features.fit_transform(x_test)
poly_predict = poly_reg.predict(x_poly_test)
poly_mse = mean_squared_error(y_test, poly_predict)
poly_rmse = np.sqrt(poly_mse)
rmses.append(poly_rmse)
# Cross-validation of degree
if min_rmse > poly_rmse:
min_rmse = poly_rmse
min_deg = deg
# Plot and present results
print('Best degree {} with RMSE {}'.format(min_deg, min_rmse))
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(degrees, rmses)
ax.set_yscale('log')
ax.set_xlabel('Degree')
ax.set_ylabel('RMSE')
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
ModuleNotFoundError: No module named 'sklearn'
When I use the command: conda install scikit-learn should this not just work? Where does anaconda install the package? I was checking the ......
Read more >Fix ModuleNotFoundError: No module named 'sklearn'
This error indicates that the scikit-learn (aka sklearn ) package was not installed, or even if it was installed for some reason it...
Read more >Modulenotfounderror no module named sklearn in Python
Fix the no module named sklearn error in Python · Save your program / notebook. Invoke terminal or the command prompt. · Package...
Read more >No module named sklearn.linear_model.logistic when I do ...
Hi,. It seems a package is missing in your code env. You can check that on Administration > Code Envs > <select the...
Read more >ModuleNotFoundError: No module named 'sklearn' in Python
The Python "ModuleNotFoundError: No module named 'sklearn'" occurs when we forget to install the scikit-learn module before importing it or ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It might be the case that you have not activate your environment correctly. Try the following commands to understand where pip3 and python come from (in our out your venv) and where scikit-learn is installed:
i understand but when i check the venv is already activated and under the folder there is already scikit_learn-1.0.1.dist-info