Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python with random forest,svm,etc I'm trying to run this code from this link http://machinelearner.net/nb.html but the problem it gives me this type of error: TypeError:

python with random forest,svm,etc I'm trying to run this code from this link http://machinelearner.net/nb.html but the problem it gives me this type of error: 
TypeError: __init__() got an unexpected keyword argument 'indices' 

this is site code:

#computer 1 from sklearn.cross_validation import KFold # R: Use library(cvFold)

# A very similar routine can be written in R using cvFold def cross_validate(model): cv = KFold(len(y), n_folds=10, indices=True, shuffle=False, random_state=None, k=None)

sum_accuracy = 0 fold = 0 for traincv, testcv in cv: result = model.fit(X[traincv], y[traincv]) p = model.predict(X[testcv]) accuracy = sum(p==y[testcv])/float(len(y[testcv])) fold = fold + 1 print "Fold accuracy ",fold,":",accuracy sum_accuracy = sum_accuracy + accuracy

print 'Overall CV Accuracy:',sum_accuracy/fold

#computer 2 from sklearn.ensemble import RandomForestClassifier # R: This is the equivalent of library(randomForest) in R

# Evaluate Random Forest rfc = RandomForestClassifier() cross_validate(rfc)

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

I tried to fix it used new library but the problem it did not show the accuracy for 10 fold cross valdiation for random forst and SVM.

the code has no error but the result did not show.

How can I show the result in this case?

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

from sklearn import cross_validation #from sklearn.cross_validation import KFold #from sklearn import cross_validation # R: Use library(cvFold)

# A very similar routine can be written in R using cvFold def cross_validate(model): num_folds = 10 num_instances = len(y) seed = None #cv = KFold(len(y), n_folds=10, indices=False, shuffle=False, random_state=None, k=None) cv = cross_validation.KFold(n=num_instances, n_folds=num_folds, random_state=seed)

sum_accuracy = 0 fold = 0 for traincv, testcv in cv: result = model.fit(X[traincv], y[traincv]) p = model.predict(X[testcv]) accuracy = sum(p==y[testcv])/float(len(y[testcv])) fold = fold + 1 print "Fold accuracy ",fold,":",accuracy sum_accuracy = sum_accuracy + accuracy

print 'Overall CV Accuracy:',sum_accuracy/fold

# the problem in this code the result did not show . it should show the acuraccy for 10 fold cross validation

from sklearn.svm import SVC # R: This is the equivalent of library(e1071) in R

# Evaluate SVM svmc = SVC() cross_validate(svmc)

from sklearn.ensemble import RandomForestClassifier # R: This is the equivalent of library(randomForest) in R

# Evaluate Random Forest rfc = RandomForestClassifier() cross_validate(rfc)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

More Books

Students also viewed these Databases questions

Question

What are the best practices for managing a large software project?

Answered: 1 week ago

Question

How does clustering in unsupervised learning help in data analysis?

Answered: 1 week ago