当前位置: 首页 > news >正文

专门做高端网站设计的云华设计wordpress彩色标签固定宽度代码

专门做高端网站设计的云华设计,wordpress彩色标签固定宽度代码,qq群优惠券里面网站怎么做的,网站源码超市文章目录1. 导入工具包2. 读取数据3. 数字特征、文字特征分离4. 数据处理Pipeline5. 尝试不同的模型6. 参数搜索7. 特征重要性筛选8. 最终完整Pipeline使用 sklearn 的 pipeline 搭建机器学习的流程 本文例子为 [Kesci] 新人赛 员工满意度预测 参考 [Hands On ML] 2. 一个完整… 文章目录1. 导入工具包2. 读取数据3. 数字特征、文字特征分离4. 数据处理Pipeline5. 尝试不同的模型6. 参数搜索7. 特征重要性筛选8. 最终完整Pipeline使用 sklearn 的 pipeline 搭建机器学习的流程 本文例子为 [Kesci] 新人赛 · 员工满意度预测 参考 [Hands On ML] 2. 一个完整的机器学习项目加州房价预测 1. 导入工具包 import numpy as np import pandas as pd %matplotlib inline import matplotlib.pyplot as plt from sklearn.model_selection import train_test_split from sklearn.model_selection import StratifiedShuffleSplit from sklearn.impute import SimpleImputer from sklearn.preprocessing import LabelEncoder from sklearn.preprocessing import OneHotEncoder from sklearn.preprocessing import LabelBinarizer from sklearn.base import BaseEstimator, TransformerMixin from sklearn.pipeline import Pipeline from sklearn.preprocessing import StandardScaler from sklearn.pipeline import FeatureUnion from sklearn.model_selection import GridSearchCV from sklearn.model_selection import cross_val_score2. 读取数据 data pd.read_csv(../competition/Employee_Satisfaction/train.csv) test pd.read_csv(../competition/Employee_Satisfaction/test.csv) data.columnsIndex([id, last_evaluation, number_project, average_monthly_hours,time_spend_company, Work_accident, package,promotion_last_5years, division, salary, satisfaction_level],dtypeobject)训练数据标签分离 y data[satisfaction_level] X data.drop([satisfaction_level], axis1)3. 数字特征、文字特征分离 def num_cat_splitor(X):s (X.dtypes object)object_cols list(s[s].index)# object_cols # [package, division, salary]num_cols list(set(X.columns) - set(object_cols))# num_cols# [Work_accident, time_spend_company, promotion_last_5years, id,# average_monthly_hours, last_evaluation, number_project]return num_cols, object_cols num_cols, object_cols num_cat_splitor(X) # print(num_cols) # print(object_cols) # X[object_cols].values特征数值筛选器 class DataFrameSelector(BaseEstimator, TransformerMixin):def __init__(self, attribute_names):self.attribute_names attribute_namesdef fit(self, X, yNone):return selfdef transform(self, X):return X[self.attribute_names].values4. 数据处理Pipeline 数字特征 num_pipeline Pipeline([(selector, DataFrameSelector(num_cols)),(imputer, SimpleImputer(strategymedian)),(std_scaler, StandardScaler()),])文字特征 cat_pipeline Pipeline([(selector, DataFrameSelector(object_cols)),(cat_encoder, OneHotEncoder(sparseFalse)),])组合数字和文字特征 full_pipeline FeatureUnion(transformer_list[(num_pipeline, num_pipeline),(cat_pipeline, cat_pipeline),]) X_prepared full_pipeline.fit_transform(X)5. 尝试不同的模型 from sklearn.ensemble import RandomForestRegressor forest_reg RandomForestRegressor() forest_scores cross_val_score(forest_reg,X_prepared,y,scoringneg_mean_squared_error,cv3) forest_rmse_scores np.sqrt(-forest_scores) print(forest_rmse_scores) print(forest_rmse_scores.mean()) print(forest_rmse_scores.std())还可以尝试别的模型 6. 参数搜索 param_grid [{n_estimators : [3,10,30,50,80],max_features:[2,4,6,8]},{bootstrap:[False], n_estimators : [3,10],max_features:[2,3,4]}, ] forest_reg RandomForestRegressor() grid_search GridSearchCV(forest_reg, param_grid, cv5,scoringneg_mean_squared_error) grid_search.fit(X_prepared,y)最佳参数 grid_search.best_params_最优模型 grid_search.best_estimator_搜索结果 cv_result grid_search.cv_results_ for mean_score, params in zip(cv_result[mean_test_score], cv_result[params]):print(np.sqrt(-mean_score), params)0.2129252723367584 {max_features: 2, n_estimators: 3} 0.19276874697889504 {max_features: 2, n_estimators: 10} 0.1865548358477794 {max_features: 2, n_estimators: 30} .......7. 特征重要性筛选 feature_importances grid_search.best_estimator_.feature_importances_选择前 k 个最重要的特征 k 3 def indices_of_top_k(arr, k):return np.sort(np.argpartition(np.array(arr), -k)[-k:])class TopFeatureSelector(BaseEstimator, TransformerMixin):def __init__(self, feature_importances, k):self.feature_importances feature_importancesself.k kdef fit(self, X, yNone):self.feature_indices_ indices_of_top_k(self.feature_importances, self.k)return selfdef transform(self, X):return X[:, self.feature_indices_]8. 最终完整Pipeline prepare_select_and_predict_pipeline Pipeline([(preparation, full_pipeline),(feature_selection, TopFeatureSelector(feature_importances, k)),(forst_reg, RandomForestRegressor()) ])参数搜索 param_grid [{preparation__num_pipeline__imputer__strategy: [mean, median, most_frequent],feature_selection__k: list(range(5, len(feature_importances) 1)),forst_reg__n_estimators : [200,250,300,310,330],forst_reg__max_features:[2,4,6,8] }]grid_search_prep GridSearchCV(prepare_select_and_predict_pipeline, param_grid, cv10,scoringneg_mean_squared_error, verbose2, n_jobs-1)训练 grid_search_prep.fit(X,y) grid_search_prep.best_params_ final_model grid_search_prep.best_estimator_预测 y_pred_test final_model.predict(test) result pd.DataFrame() result[id] test[id] result[satisfaction_level] y_pred_test result.to_csv(rf_ML_pipeline.csv,indexFalse)以上只是粗略的大体框架还有很多细节大家多指教 我的CSDN博客地址 https://michael.blog.csdn.net/ 长按或扫码关注我的公众号Michael阿明一起加油、一起学习进步
http://www.yutouwan.com/news/37545/

相关文章:

  • 中国建设银行大沥网站线上 网站建设 商务信息
  • 张家港杨舍网站制作永兴网站开发
  • 部队网站建设建议农村淘宝官网首页
  • app下载网站模板网站转化率是什么意思
  • 网站建设与维护模板株洲58同城网站建设电话
  • 微信网站链接网站建设wordpress批量 添加别名
  • 番禺网站建设公司排名wordpress采集豆瓣插件
  • 专业商城网站设计制作广东企业网站备案
  • 在自己的网站上怎么做淘宝客建盏哪家好
  • 免费购物网站系统江门建设建筑网站
  • 下载网站后怎么做的英文版的wordpress能否改中文版
  • 博客优化网站seo怎么写郴州新网招聘手机版
  • discuz门户网站模板wordpress自定义页面跳转
  • 表白网站制作系统源码网页制作常用软件
  • 青岛住房和城乡建设 网站wordpress 禁用响应
  • 有什么好的手机推荐网站浙江荣盛建设集团网站
  • 主流电商网站开发框架网站开发过程中的方法
  • 做网站公司大连免费心理咨询师24小时在线咨询
  • 荆州网站建设价格35互联做的网站如何
  • 加强网站建设考察交流网站推广排名公司
  • 杭州建站模板系统国内网站 备案
  • 百度怎样可以搜到自己的网站什么网站做视频赚钱
  • 网站编程薪资三明网站建设公司
  • 赣州市铁路建设办公室网站wordpress自定义作者连接
  • 免费快速建站工具怎么为网站做外链
  • 上海专业做网站推广的公司苏州工业园区服务外包职业学院
  • 绵阳网站维护托管网站的发布方案有哪些
  • 昆山网站建设多少钱在家建设一个网站需要什么
  • 免费做网站刮刮卡wordpress伪静态卡死
  • 龙华网站建设推广外包物流公司怎么做网站