第九篇:机器学习基础:集成学习算法与SVM支持向量机的代码实操及调参

本文介绍了机器学习中的集成学习与支持向量机(SVM)的应用。通过读取数据、预处理,利用Pipeline构建模型,并详细讲解了SVM和随机森林的参数设置。接着,采用GridSearchCV进行参数调优,最后对SVM和随机森林模型进行了评估和预测。
摘要由CSDN通过智能技术生成

导入相应的标准库

	import pandas as pd
	from sklearn.model_selection import train_test_split
	from sklearn.pipeline import Pipeline
	from sklearn.preprocessing import StandardScaler
	from sklearn.decomposition import PCA
	from sklearn.svm import SVC
	from sklearn.model_selection import GridSearchCV
	from sklearn.ensemble import RandomForestClassifier
	import datetime
	from sklearn.metrics import confusion_matrix, classification_report

第一步:读取数据

	# local_path = pd.read_csv("...")
    local_path = pd.read_csv("./alipay_huabei_GS1.csv")
    # 查看一下 文件内容的前几行信息
    print(local_path.head())
    # 文件过大,进行随机抽样, frac确定抽取的比例, random_state以确保可重复性的例子。
    local_path = pd.DataFrame.sample(local_path, frac=0.3, random_state=1)
    # 另一种对文件处理对方式:选择前1000行数据
    # local_path = local_path[0: 1000]

第二步: 数据预处理

    # 2.1) 筛选特征值与目标值
    # 属性特征值的列范围为,第二列到倒数第二列
    x_data = local_path.iloc[:, 1: -1]
    # print(x_data.head())

    # 目标值为最后一列
    x_target = local_path['default.payment.next.month']
    # print(x_target.head())
    # 2.2) 数据集划分,要注意划分的之后的变量的接收顺序
    x_train, x_test, y_train
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值