Reputation: 1197
I am using python 2.7. Documentation for SVC.
When I try the following:
from sklearn.svm import SVC
base_learner = SVC(random_state=4,probability=True)
It throws the following error:
TypeError: Argument 'kernel' has incorrect type (expected str, got unicode)
So I thought I would try this:
from builtins import str
from sklearn.svm import SVC
base_learner = SVC(kernel=str('rbf'), random_state=4,probability=True)
Still doesn't recognize the kernel. What am I doing wrong?
Upvotes: 0
Views: 298
Reputation: 18221
What you are doing should work in the newest versions of Python 2.7 and scikit-learn without having to resort to manually dealing with string conversion, so this sounds like a Python environment gone awry.
If you are using conda to manage your environments, you can try creating one from scratch through the following steps:
Open Anaconda Prompt (or any command prompt from which you can run conda).
Run conda create --name py27sklearn
to create a new environment
Activate that environment by running activate py27sklearn
(or conda activate py27sklearn
)
Install Python 2.7 by running conda install python=2.7
.
Install scikit-learn by running conda install scikit-learn
.
Run a Python interpreter by running python
.
Verify that your code runs as expected.
You should see something like the following:
(py27sklearn) $ python
Python 2.7.15 |Anaconda, Inc.| (default, May 1 2018, 18:37:09) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from sklearn.svm import SVC
>>> SVC(random_state=4, probability=True)
SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,
decision_function_shape='ovr', degree=3, gamma='auto', kernel='rbf',
max_iter=-1, probability=True, random_state=4, shrinking=True, tol=0.001,
verbose=False)
Upvotes: 1