60 lines
1.6 KiB
Python
60 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
Created on Sun May 29 12:21:34 2022
|
|
|
|
@author: tanu
|
|
"""
|
|
from sklearn.svm import SVC
|
|
from sklearn.datasets import make_classification
|
|
|
|
from yellowbrick.model_selection import RFECV
|
|
|
|
# Instantiate RFECV visualizer with a linear SVM classifier
|
|
visualizer = RFECV(SVC(kernel='linear', C=1))
|
|
|
|
visualizer.fit(X[numerical_FN], y) # Fit the data to the visualizer
|
|
visualizer.show()
|
|
|
|
|
|
numerical_ix = X.select_dtypes(include=['int64', 'float64']).columns
|
|
numerical_ix
|
|
categorical_ix = X.select_dtypes(include=['object', 'bool']).columns
|
|
categorical_ix
|
|
|
|
# Determine preprocessing steps ~ var_type
|
|
var_type = 'mixed'
|
|
var_type = 'numerical'
|
|
|
|
if var_type == 'numerical':
|
|
t = [('num', MinMaxScaler(), numerical_ix)]
|
|
|
|
if var_type == 'categorical':
|
|
t = [('cat', OneHotEncoder(), categorical_ix)]
|
|
|
|
if var_type == 'mixed':
|
|
t = [('cat', OneHotEncoder(), categorical_ix)
|
|
, ('num', MinMaxScaler(), numerical_ix)]
|
|
|
|
t = [('num', MinMaxScaler(), numerical_ix)
|
|
, ('cat', OneHotEncoder(), categorical_ix)]
|
|
|
|
col_transform = ColumnTransformer(transformers = t
|
|
, remainder='passthrough')
|
|
#--------------ALEX help
|
|
# col_transform
|
|
# col_transform.fit(X)
|
|
# test = col_transform.transform(X)
|
|
# print(col_transform.get_feature_names_out())
|
|
|
|
# foo = col_transform.fit_transform(X)
|
|
Xm = col_transform.fit_transform(X)
|
|
# (foo == test).all()
|
|
#-----------------------
|
|
|
|
visualizer.fit(Xm, y) # Fit the data to the visualizer
|
|
visualizer.show()
|
|
|
|
|
|
visualizer.fit(X[numerical_FN], y) # Fit the data to the visualizer
|
|
visualizer.show()
|