Skip to content

Instantly share code, notes, and snippets.

View ashishpatel26's full-sized avatar
🏠
Working from home

Ashish Patel ashishpatel26

🏠
Working from home
View GitHub Profile
@ashishpatel26
ashishpatel26 / pythonista.rst
Created May 3, 2018 05:33 — forked from skopp/pythonista.rst
Code like a Pythonista - Tutorial

Code Like a Pythonista: Idiomatic Python

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
from sklearn.datasets import load_iris
#import IRIS data set
Iris = load_iris()
# Feature matrix
Iris.data
#Target vector
Iris.target
from sklearn.preprocessing import StandardScaler
# Standardization, return data is normalized
StandardScaler().fit_transform(iris.data)
from sklearn.preprocessing import MinMaxScaler
#interval scaling, the return value is the data scaled to the [0, 1] interval
MinMaxScaler().fit_transform(iris.data)
from sklearn.preprocessing import Normalizer
#Normalization, return value is normalized data
Normalizer().fit_transform(iris.data)
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)
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)))
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)))
from sklearn.preprocessing import PolynomialFeatures
# polynomial conversion
# Parameterdegree is degree, default is 2
PolynomialFeatures().fit_transform(iris.data)