Feature Engineering Made Easy 笔记 Chapter5

Chapter 5 Feature Selection

预测性能指标

  1. 真阳性率和假阳性率
  2. 绝对平均误差(回归)
  3. R 2 = 1 − S S r e s S S t o t a l R^2 = 1-\frac{SS_{res}}{SS_{total}} R2=1SStotalSSres coefficient of determination
    S S r e s = ∑ ( y i − y ^ ) 2 SS_{res} = \sum(y_i-\widehat{y})^2 SSres=(yiy )2
    S S t o t a l = ∑ ( y i − y ‾ ) 2 SS_{total} = \sum(y_i-\overline{y})^2 SStotal=(yiy)2
    模型越好,越接近1
  4. 训练时间
  5. 预测新数据时间

基于统计的特征选择

  1. Pearson Correlation C o v ( x , y ) σ x σ y \frac{Cov(x,y)}{\sigma_x \sigma_y} σxσyCov(x,y) 衡量两个变量的线性关系。
  2. Hypothesis Test:
    Anova F value
    chi-squared
    使用SelectKBest
k_best = SelectKBest(f_classif, k=5)
k_best.fit_transform(X, y)

基于机器学习模型选择

使用机器学习 SelectFromModel
Decision Tree
logisitic regression(针对回归任务)
SVC(针对二分数据集)

tree = DecisionTreeClassifier()
tree.fit(X, y)
tree_pipe_params = {'classifier__max_depth': [1, 3, 5, 7]}
importances = pd.DataFrame({'importance': tree.feature_importances_, 'feature':X.columns}).sort_values('importance', ascending=False)
tree_pipe_params = {'classifier__max_depth': [1, 3, 5, 7]}
select_from_model = SelectFromModel(DecisionTreeClassifier(), 
                                    threshold=.05)
selected_X = select_from_model.fit_transform(X, y)                                   
from sklearn.pipeline import Pipeline
select_from_pipe = Pipeline([('select', SelectFromModel(DecisionTreeClassifier())), 
                             ('classifier', d_tree)])
select_from_pipe_params = deepcopy(tree_pipe_params)
select_from_pipe_params.update({
              'select__threshold': [.01, .05, .1, "mean", "median", "2.*mean"],
              'select__estimator__max_depth': [None, 1, 3, 5, 7]
              })
print select_from_pipe_params
# not better than original
get_best_model_and_accuracy(select_from_pipe, 
                            select_from_pipe_params, 
                            X, y)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Feature engineering is the process of creating new features or variables from existing data to improve the performance of a machine learning model. In Python, there are various libraries and tools available for feature engineering. Some of the popular ones are: 1. Pandas: Pandas is a library that provides data structures for efficient data analysis. It provides various functions to manipulate data, such as merging, filtering, and reshaping data. Pandas can be used for feature engineering by creating new features based on existing data, such as computing summary statistics, transforming categorical variables, and combining multiple features. 2. Scikit-learn: Scikit-learn is a popular machine learning library in Python that provides a wide range of machine learning algorithms and tools. It also provides various feature engineering functions, such as feature scaling, feature selection, and dimensionality reduction. 3. Numpy: Numpy is a library that provides numerical computing tools in Python. It provides various functions for mathematical operations on arrays, such as computing mean, standard deviation, and correlation. Numpy can be used for feature engineering by creating new features based on mathematical operations on existing data. 4. Featuretools: Featuretools is a library that provides automated feature engineering tools. It automatically creates new features based on existing data and domain knowledge. It can be used for large datasets with complex relationships between variables. 5. PySpark: PySpark is a Python library that provides tools for distributed computing using Apache Spark. It provides various functions for data manipulation and transformation, such as filtering, aggregation, and join. PySpark can be used for feature engineering on large datasets that cannot be processed on a single machine. Overall, feature engineering is an essential step in the machine learning pipeline, and Python provides a wide range of tools and libraries for this task.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值