how to import modules which are in form of
"from sklearn.tree import DecisionTreeRegressor" in Pyscript?
The way you import modules works as follows:
Include the relevant package in the environment
<py-env>
- scikit-learn
</py-env>
Import the module as you would do it in any other python file
<py-script>
from sklearn.tree import DecisionTreeClassifier
dt = DecisionTreeClassifier()
...
</py-script>
Related
I have created a class inside a python package. The problem is that the class uses the numpy library which is not seen when imported.
'''
import numpy as np
class NN:'''
and in the init class I wrote
'''
from net.NN import NN
'''
but when I import the package in my jupyter notebook
'''
from net import NN
'''
and I initialize the class it just gives me an error "No module named np"
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import check_util.checker as checker
from IPython.display import clear_output
from PIL import Image
import os
import time
import re
from glob import glob
import shutil
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow import keras
print('tensorflow version: {}'.format(tf.__version__))
print('GPU available: {}'.format(tf.test.is_gpu_available()))
When I run this, there is no error. But it shows as indefinitely in progress.
(Current 630..631..632...sec)
guys am having import error while trying to import KNeighborsClassifier from sklearn.neighbors import k
its showing the following errors
ImportError: cannot import name 'kNeighborsClassifier' from 'sklearn.neighbors' (/home/themysteriouschemeng/anaconda3/lib/python3.7/site-packages/sklearn/neighbors/init.py)
You have used small k instead of capital K in KNeighborsClassifier.
Your import -from sklearn.neighbors import kNeighborsClassifier
Right import - from sklearn.neighbors import KNeighborsClassifier
Replace small k with capital K in KNeighborsClassifier and this will fix your import issue.
Can you add the code you are using?
Btw the basic code to import is
from sklearn.neighbors import KNeighborsClassifier
model = KNeighborsClassifier(n_neighbors=4)
I am running a Jupyter notebook but I do not get any output or error telling me if something is wrong. I have tried installing tornado as some other threads have suggested as well as the command pip install notebook --upgrade
While I do not think there is a problem with my code here it is.
Any help is truly appreciated.
import os
import numpy as np
import pandas as pd
import cv2
from glob import glob
import tensorflow as tf
from tensorflow.keras.layers import *
from tensorflow.keras.applications import MobileNetV2
from tensorflow.keras.callbacks import ModelCheckpoint, ReduceLROnPlateau
from tensorflow.keras.optimizers import Adam
from sklearn.model_selection import train_test_split
if __name__=="_main_":
path="dog-breed-identification/"
train_path = os.path.join(path, "train/*")
train_path = os.path.join(path, "test/*")
train_path = os.path.join(path, "labels.csv")
labels_df = pd.read_csv(labels_path)
#name of column in csv
breed = labels_df["breed"].unique()
print("Number of Breed: ", len(breed))
enter code here
As it turns out, if I delete
if __name__=="_main_":
I get an output
Trying to import Imputer from sklearn.preprocessing,
import pandas as pd
dataset = pd.read_csv('Data.csv')
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, 3].values
#PART WHERE ERROR OCCURS:-
from sklearn.preprocessing import Imputer
Shows "ImportError: cannot import name 'Imputer' from 'sklearn.preprocessing' (/home/codeknight13/anaconda3/lib/python3.7/site-packages/sklearn/preprocessing/_init_.py)"
from sklearn.preprocessing import Imputer was deprecated with scikit-learn v0.20.4 and removed as of v0.22.2. See the sklean changelog.
from sklearn.impute import SimpleImputer
import numpy as np
imputer = SimpleImputer(missing_values=np.nan, strategy='mean')
pip install scikit-learn==0.20.4 or conda install scikit-learn=0.20.4 are not a good options because scikit-learn==0.20.4 is more than 3 years out of date.