This file contains hidden or 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
| def read_idx(filename): | |
| with gzip.open(filename, 'rb') as f: | |
| zero, data_type, dims = struct.unpack('>HBB', f.read(4)) | |
| shape = tuple(struct.unpack('>I', f.read(4))[0] for d in range(dims)) | |
| return np.fromstring(f.read(), dtype=np.uint8).reshape(shape) | |
| train_x = read_idx('./fashion-mnist/data/fashion/train-images-idx3-ubyte.gz') | |
| train_y = read_idx('./fashion-mnist/data/fashion/train-labels-idx1-ubyte.gz') | |
| test_x = read_idx('./fashion-mnist/data/fashion/t10k-images-idx3-ubyte.gz') | |
| test_y = read_idx('./fashion-mnist/data/fashion/t10k-labels-idx1-ubyte.gz') |
This file contains hidden or 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
| pd = pd.DataFrame(fetch_california_housing.data, columns=fetch_california_housing.feature_names) | |
| pd['AveHouseVal'] = (fetch_california_housing.target)*100000 |
This file contains hidden or 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
| (mu, sigma) = norm.fit(residuals) | |
| print( '\n mu = {:.2f} and sigma = {:.2f}\n'.format(mu, sigma)) | |
| _, p_value = stats.shapiro(residuals) | |
| print('Shapiro-Wilk test p-value: ' + str(p_value)) | |
| # Get the fitted parameters used by the function | |
| sns.distplot(residuals , fit=norm) | |
| plt.legend(['Normal dist. ($\mu=$ {:.2f} and $\sigma=$ {:.2f} )'.format(mu, sigma)], loc='best') | |
| plt.ylabel('Frequency') |
This file contains hidden or 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
| X = pd[['MedInc', 'Latitude', 'AveRooms']] | |
| Y = pd['AveHouseVal'] | |
| X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size = 0.2, random_state=5) | |
| lin_model = LinearRegression() | |
| lin_model.fit(X_train, Y_train) | |
| # model evaluation for training set | |
| y_train_predict = lin_model.predict(X_train) | |
| rmse = (np.sqrt(mean_squared_error(Y_train, y_train_predict))) |
This file contains hidden or 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
| corrmat = pd.corr() | |
| plt.subplots(figsize=(12,9)) | |
| mask = np.zeros_like(corrmat, dtype=np.bool) | |
| mask[np.triu_indices_from(mask)] = True | |
| sns.heatmap(corrmat, vmax=0.9, square=True, annot=True, mask=mask, cbar_kws={"shrink": .5}) |
This file contains hidden or 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
| plt.figure(figsize=(10,8)) | |
| plt.scatter(pd['Latitude'], pd['Longitude'], c=pd['AveHouseVal'], s=pd['Population']/100) | |
| plt.colorbar() |
This file contains hidden or 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
| pd.isnull().sum() |
This file contains hidden or 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
| pd = pd.DataFrame(fetch_california_housing.data, columns=fetch_california_housing.feature_names) | |
| pd.head() |
This file contains hidden or 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
| print(fetch_california_housing.DESCR) |
This file contains hidden or 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
| fetch_california_housing = fetch_california_housing() | |
| print(fetch_california_housing.keys()) |