labelencoder_X_1 = LabelEncoder() X[:,1]=labelencoder_X_1.fit_transform(X[:,1]) labelencoder_X_2 = LabelEncoder() X[:,2]=labelencoder_X_2.fit_transform(X[:,2]) onehotencoder = OneHotEncoder(categorical_features =[1]) X=onehotencoder.fit_transform(X).toarray() X=X[:,1:] #splitting from sklearn.model_selection import train_test_split X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=0) #FeatureScaling from sklearn.preprocessing import StandardScaler sc =StandardScaler() X_train = sc.fit_tranform(X_train) X_test = sc.transform(X_test) #Making ANN #Importing Keras libraries and packages import keras from keras.models import Sequential from keras.layers import Dense from keras.layers import Dropout #Initializing ANN classifier = Sequential() #Adding input layer and first hidden layer classifier.add(Dense(output_dim=6,init='uniform',activation='relu',input_dim=11)) classifier.add(Dropout(p=0.1))
# Splitting the dataset into the Training set and Test set from sklearn.cross_validation import train_test_split trainx, testx, trainy, testy = train_test_split(X, y, test_size = 0.2, random_state = 0) # Feature Scaling from sklearn.preprocessing import StandardScaler sx = StandardScaler() trainx = sx.fit_transform(trainx) trainx = sx.transform(trainx) x = sx.fit_transform(x) sy = StandardScaler() trainy = sy.fit_transform(trainy) y = y.reshape(-1, 1) y = sy.fit_tranform(y) # Predicting the Test set results predicty = regressor.predict(x/6.5) # Correlation / Feature Importance import seaborn as sns sns.set(style="white") sns.set(style="whitegrid", color_codes=True) # Correlation Heatmap / Visualization dataset.corr() sns.heatmap(dataset.corr()) # Scatter Plot Visualization
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @author:Wang Yan @ide:PyCharm @time:2019/5/8 21:10 """ from sklearn.datasets import load_wine from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler wine = load_wine() print wine.target print wine.data.shape x_train, x_test, y_train, y_test = train_test_split(wine.data, wine.target, test_size=0.3) sc = StandardScaler() # 根据对之前部分trainData进行fit的整体指标,对剩余的数据(testData)使用同样的均值、方差、最大最小值等指标进行 # 转换transform(testData),从而保证train、test处理方式相同。 sc.fit_tranform(x_train) sc.tranform(x_test)