Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help converting this code to python Rm(list=1s ()) data=read.table(\'iris.d

ID: 3885363 • Letter: N

Question

Need help converting this code to python

Rm(list=1s ()) data=read.table('iris.data', sep=', ') K=10: # K-Fold CV c1=as.numeric (data [, nco (data)]) # class label as numeric e.g. 1 2 3.. C=length (unique(cl)): N=nrow(data) #C: # of class, N: # of instances x=cbind(as.matrix (data[, -nco (data)]), matrix (1, nrow=N, nco -1)) y=matrix(0, nrow=N, ncol=c) for (i in 1: N) y[i, c [i]]=1 k = N/K result=matrix(0, nrow=100, ncol=1) # to store 100 CV's results for (j in 1: 100) {# 100 times CVs ridx=sample(N) local_result=matrix(0, nrow=K, nco1=1) # to store 10 Fold CVs for (i in 1: K){# for each fold s=(1+k*(i - 1)): (i * k) # k sequential index testy=y[ridx[s], ];testX = X[ridx[s], ] trainy=y[-ridx[s], ]: trainX = X[-ridx[s], ] bs = solve (t (trainx)%*%trai nX)%*%t(trainx)%*%trainy local_result [i] = length(which (apply(testX%*%bs, 1, which. max) == apply(testy, 1, which. max)))/k ## Accuracy for each fold } result [j] = mean(local_result) } print(mean(result)) print(sd(result))

Explanation / Answer

I am working on it. I will post the complete solution as soon as i am done.

import numpy as np
import pandas as pd
from sklearn.datasets import load_iris
iris = load_iris()

df = pd.DataFrame(data= np.c_[iris['data'], iris['target']],
columns= iris['feature_names'] + ['Species'])


df['Species']=df['Species']+1
  
df.Species = df.Species.astype(int)
#print(df['Species'])
K=10
C=len(df.Species.unique())
print(C)
N=df.shape[0]

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote