'module' object has no attribute 'svc'

12,087

Solution 1

svc = svm.SVC(kernel='linear', C=1, gamma=1)

Note that capital C.

See the docs.

Solution 2

You can try

from sklearn.svm import SVC

then

model = SVC(kernel='linear', c=1, gamma=1)

worked fine for me

Solution 3

You can try this:

from sklearn import svm
clf = svm.SVC(kernel='linear', C=1,gamma=1)

'C' must be in capital

Solution 4

The error come from you code below:

model = svm.svc(kernel='linear', c=1, gamma=1) 

After you use :

svc = svm.SVC()

svc is an object produced by svm.SVC(). So I guess what you want is :

model = svc(kernel='linear', c=1, gamma=1)

or

model = svm.SVC(kernel='linear', c=1, gamma=1)

Wish this could help~

Solution 5

Your problem originate from the fact that you call:

model = svm.svc(kernel='linear', c=1, gamma=1) 

with lowercase svc in svm.svc, which should be svm.SVC. Additionally, as Alex Hall noted, you call c=1 with in lower case which should be C=1. Giving:

model = svm.SVC(kernel='linear', C=1, gamma=1) 
Share:
12,087

Related videos on Youtube

Anagha
Author by

Anagha

Updated on June 04, 2022

Comments

  • Anagha
    Anagha almost 2 years
    import pandas as pd
    from sklearn import svm
    
    ### Read the CSV ###
    df = pd.read_csv('C:/Users/anagha/Documents/Python Scripts/sampleData.csv')
    df
    
    from sklearn.cross_validation import train_test_split
    train, test = train_test_split(df, train_size = 0.8)
    train
    test
    
    x_column=['Userid','day_of_week','hour_of_day','minute_of_hour']
    y_column = ['thermostat']
    
    svc = svm.SVC()
    model = svm.svc(kernel='linear', c=1, gamma=1) 
    

    I'm getting an error AttributeError: 'module' object has no attribute 'svc'. Tried many techniques, but none of them are working. I'm new to python, and would really appreciate the help

  • dorien
    dorien almost 5 years
    This still does not work for me. So strange. Tried every solution here.
  • Alex Hall
    Alex Hall almost 5 years
    What exactly is your code and what error do you get?
  • Ahx
    Ahx over 3 years
    Please be reminded that for a single-state answer, you can also use the comment section of the answer. For instance, in the comment section "You can convert svm to SVC"

Related