Tag Archives: sklearn

[Solved] pyinstaller: error: unrecognized arguments: sklearn

How to Solve Error: pyinstaller: error: unrecognized arguments: sklearn

 

Solution:

Go to cmd
pyinstaller main.py  –hidden-import PySide2.QtXml –hidden-import sklearn –hidden-import sklearn.ensemble._forest –icon=”logo.ico”
Add the unrecognized sklearn to hidden import –hidden-import sklearn
The issue will be fixed.

 

[Solved] fit function error: KeyError: ‘squared_error‘

critical code

param_grid_simple = {"criterion": ["squared_error","poisson"]
                     , 'n_estimators': [*range(20,100,5)]
                     , 'max_depth': [*range(10,25,2)]
                     , "max_features": ["log2","sqrt",16,32,64,"auto"]
                     , "min_impurity_decrease": [*np.arange(0,5,10)]
                    }
search = GridSearchCV(estimator=reg
                     ,param_grid=param_grid_simple
                     ,scoring = "neg_mean_squared_error"
                     ,verbose = True
                     ,cv = cv
                     ,n_jobs=-1)
search.fit(X,y)                  

Error reporting information

~/anaconda3/lib/python3.8/site-packages/sklearn/ensemble/_forest.py in _parallel_build_trees(tree, forest, X, y, sample_weight, tree_idx, n_trees, verbose, class_weight, n_samples_bootstrap)
    166                                                         indices=indices)
    167 
--> 168         tree.fit(X, y, sample_weight=curr_sample_weight, check_input=False)
    169     else:
    170         tree.fit(X, y, sample_weight=sample_weight, check_input=False)

~/anaconda3/lib/python3.8/site-packages/sklearn/tree/_classes.py in fit(self, X, y, sample_weight, check_input, X_idx_sorted)
   1240         """
   1241 
-> 1242         super().fit(
   1243             X, y,
   1244             sample_weight=sample_weight,

~/anaconda3/lib/python3.8/site-packages/sklearn/tree/_classes.py in fit(self, X, y, sample_weight, check_input, X_idx_sorted)
    334                                                          self.n_classes_)
    335             else:
--> 336                 criterion = CRITERIA_REG[self.criterion](self.n_outputs_,
    337                                                          n_samples)
    338 

KeyError: 'squared_error'

analysis

KeyError error will be caused when accessing a key that is not in dict, then the parameter of criterion is squared_error may not exist. Since the parameter value is known, it is speculated that there may be a problem with your own sklearn version. Check your version of sklearn is 0.23, while the official version has already been above 1.0.

Solution:

See the official document of sklearn

scikit-learn 1.1. dev0
scikit-learn 0.23.2

You can see that different versions of the criterion parameter have different values, which can be considered

1. Change the value to the value of the corresponding version, such as’ MSE ‘.

2. Change the version of sklearn directly.

Because the official document says, “MSE” is in V1.0 has been deprecated and will be removed in version 1.2. “Squared_error” is equivalent. Therefore, the method of upgrading sklearn is adopted.

pip install scikit-learn==1.0.1

[Solved] graphviz Error: failed to execute [‘dot’, ‘-Tsvg’], make sure the Graphviz executables are on your systems’ PATH

 

graphviz error: failed to execute [‘dot’, ‘-Tsvg’], make sure the Graphviz executables are on your systems’ PATH

1. Download graphviz

Go to https://graphviz.org/download/ to download graphviz (64-bit system must choose 64-bit Installer, can not choose ZIP)

2. Installation

In the following interface, you must select the red option (if not selected, you can only manually add environment variables later), and then you can finish all the way.

3. Test

win + R, type cmd, open the cmd window, use dot -version test, can display the version information is installed successfully
(Do not blindly open CMD, if the open is C:\WINDOWS\system32> that can not be measured)

Note: if not, restart anaconda.

[Solved] scikit-learn Error: ModuleNotFoundError: No module named ‘sklearn.utils.linear_assignment_’

Record some scikit-learn errors

The questions are as follows:

ModuleNotFoundError: No module named ‘sklearn. utils. linear_ assignment_’

Solution:
the sciki-learn version here is too high (it was 1.0.1 before, and it should be made into 0.19.X or before).
my operation is directly in the compiler In (IDE), set -> project: XXXXXX -> Python interpreter, and directly reinstall the corresponding version.

Anaconda upgrade sklearn version

Project github address: bitcarmanlee easy-algorithm-interview-and practice
welcome to star, message, study and progress together
When you call model_selection for Sklearn, you find a module with no Model_selection in Sklearn. Upon inspection, the SkLearn version in Anaconda was found to be too low, at version 0.17. So sklearn started to upgrade.
1. View the original version
First use the conda list command to check the existing version:

Sure enough, version 0.17.1 was too low, so it was time to upgrade.
2. Upgrade to the latest version
Use the conda update scikit-learn command to update the version of sklearn. Before you update, you will be prompted for what version to update to.

As you can see, the latest version is 0.19.0
Then confirm and start updating.

Due to the large number of packages that need to be updated this time, it will take quite a long time…
Once the update is complete, then use the Model_Selection package, and it’s OK to use 1