This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.linear_model import LogisticRegression | |
class LR(LogisticRegression): | |
def __init__(self, threshold=0.01, dual=False, tol=1e-4, C=1.0, | |
fit_intercept=True, intercept_scaling=1, class_weight=None, | |
random_state=None, solver='liblinear', max_iter=100, | |
multi_class='ovr', verbose=0, warm_start=False, n_jobs=1): | |
#Thresold | |
self.threshold = threshold |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.datasets import load_iris | |
#import IRIS data set | |
Iris = load_iris() | |
# Feature matrix | |
Iris.data | |
#Target vector | |
Iris.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.preprocessing import StandardScaler | |
# Standardization, return data is normalized | |
StandardScaler().fit_transform(iris.data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.preprocessing import MinMaxScaler | |
#interval scaling, the return value is the data scaled to the [0, 1] interval | |
MinMaxScaler().fit_transform(iris.data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.preprocessing import Normalizer | |
#Normalization, return value is normalized data | |
Normalizer().fit_transform(iris.data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.preprocessing import Binarizer | |
# Binarization, a threshold value is set to 3, the return data is binarized | |
Binarizer(threshold=3).fit_transform(iris.data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.preprocessing import OneHotEncoder | |
# Dummy encoding, the target value of IRIS data set, return the value of the dummy data encoding | |
OneHotEncoder().fit_transform(iris.target.reshape((-1,1))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from numpy import vstack, array, nan | |
from sklearn.preprocessing import Imputer | |
#missing value calculation, return value is the data after calculating the missing value | |
# The parameter missing_value is a representation of the missing value. The default is NaN. | |
#Parameters is a missing value filling method, the default is mean (mean) | |
Imputer().fit_transform(vstack((array([nan, nan, nan, nan]),iris.data))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.preprocessing import PolynomialFeatures | |
# polynomial conversion | |
# Parameterdegree is degree, default is 2 | |
PolynomialFeatures().fit_transform(iris.data) |
OlderNewer