Python和R代码机器学习算法速查对比表.docx





《Python和R代码机器学习算法速查对比表.docx》由会员分享,可在线阅读,更多相关《Python和R代码机器学习算法速查对比表.docx(5页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Python和R代码机器学习算法速查对比表这里给出的速查表收集了10个最为常用的机器学习算法,附上了Python和R代码。考虑到机器学习方法在建模中得到了更多的运用,以下速查表可以作为代码指南来帮助你掌握机器学习算法运用。机器学习算法类 型监督学习非监督学习增强学习决策树K-近邻算法随机决策森林Logistics回归分析Apriori算法K-均值算法系统聚类马尔科夫决策过程增强学习算法(Q-学习)线性回归#Import Library#Import other necessary libraries like pandas,#numpy.from sklearn import linear_m
2、odel#Load Train and Test datasets#Identify feature and response variable(s) and#values must be numeric and numpy arraysx_train=input_variables_values_training_datasets y_train=target_variables_values_training_datasets x_test=input_variables_values_test_datasets#Create linear regression objectlinear
3、= linear_model.LinearRegression()#Train the model using the training sets and #check scorelinear.fit(x_train, y_train) linear.score(x_train, y_train)#Equation coefficient and Intercept print(Coefficient: n, linear.coef_) print(Intercept: n, linear.intercept_) #Predict Outputpredicted= linear.predict
4、(x_test)#Load Train and Test datasets#Identify feature and response variable(s) and#values must be numeric and numpy arraysx_train - input_variables_values_training_datasetsy_train - target_variables_values_training_datasetsx_test - input_variables_values_test_datasetsx - cbind(x_train,y_train)#Trai
5、n the model using the training sets and#check scorelinear - lm(y_train ., data = x)summary(linear)#Predict Outputpredicted= predict(linear,x_test)逻辑回归#Import Libraryfrom sklearn.linear_model import LogisticRegression#Assumed you have, X (predictor) and Y (target)#for training data set and x_test(pre
6、dictor)#of test_dataset#Create logistic regression objectmodel = LogisticRegression()#Train the model using the training sets#and check scoremodel.fit(X, y)model.score(X, y)#Equation coefficient and Interceptprint(Coefficient: n, model.coef_)print(Intercept: n, model.intercept_)#Predict Outputpredic
7、ted= model.predict(x_test)x - cbind(x_train,y_train)#Train the model using the training sets and check #scorelogistic - glm(y_train ., data = x,family=binomial) summary(logistic)#Predict Outputpredicted= predict(logistic,x_test)决策树#Import Library#Import other necessary libraries like pandas, numpy.
8、from sklearn import tree#Assumed you have, X (predictor) and Y (target) for#training data set and x_test(predictor) of #test_dataset#Create tree objectmodel = tree.DecisionTreeClassifier(criterion=gini) #for classification, here you can change the #algorithm as gini or entropy (information gain) by#
9、default it is gin#model = tree.DecisionTreeRegressor() for#regression#Train the model using the training sets and check #scoremodel.fit(X, y)model.score(X, y)#Predict Outputpredicted= model.predict(x_test)#Import Librarylibrary(rpart)x -cbind(x_train,y_train)#grow treefit - rpart(y_train ., data = x
10、,method=class) summary(fit)#Predict Outputpredicted= predict(fit,x_test)支持向量机#Import Libraryfrom sklearn import svm#Assumed you have, X (predictor) and Y (target) for #training data set and x_test(predictor) of test_dataset#Create SVM classification objectmodel = svm.svc()#there are various options
11、associatedwith it, this is simple for classification.#Train the model using the training sets and check #scoremodel.fit(X, y)model.score(X, y)#Predict Outputpredicted= model.predict(x_test)#Import Librarylibrary(e1071)x - cbind(x_train,y_train) #Fitting modelfit -svm(y_train ., data = x) summary(fit
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Python 代码 机器 学习 算法 查对

限制150内