def visual_inspection(raw_signal_list, filtered_signal_list, begin_sec, end_sec): import matplotlib.pylot as plt for raw_signal, filtered_signal in zip(raw_signal_list, filtered_signal_list): plt.figure(figsize=(20, 20)) plt.plot(raw_signal.T) plt.plot(filterd_signal.T) plt.xlim(begin_sec * 1000, end_sec * 1000) plt.legend(['raw', 'filtered']) plt.show()
from matplotlib.colors import ListedColormap X_set, y_set = X_train, y_train X1, X2 = np.meshgrid( np.arange(start=X_set[:, 0].min() - 1, stop=X_set[:, 0].max() + 1, step=0.01), np.arange(start=X_set[:, 1].min() - 1, stop=X_set[:, 1].max() + 1, step=0.01)) plt.contourf(X1, X2, classifer.predict(np.array([X1.ravel(), X2.ravel()]).T).reshape(X1.shape), alpha=0.75, cmap=ListedColormap(('red', 'green'))) plt.xlim(X1.min(), X1.max()) plt.ylim(X2.min(), X2.max()) for i, j in enumerate(np.unique(y_set)): plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], c=ListedColormap(('red', 'green'))(i), label=j) plt.title('Classifier (Training set)') plt.xlabel('Age') plt.ylabel('Estimated Salary') plt.legend() plt.show() # Visualising the Test set results from matplotlib.colors import ListedColormap X_set, y_set = X_test, y_test
stdout.flush() stdout.write("\n") # Calculate and print the position of minimum in MSE msemin = np.argmin(mse) print("Suggested number of components: ", msemin+1) stdout.write("\n") if plot_components is True: with plt.style.context(('ggplot')): plt.plot(component, np.array(mse), '-v', color = 'blue', mfc='blue') plt.plot(component[msemin], np.array(mse)[msemin], 'P', ms=10, mfc='red') plt.xlabel('Number of PLS components') plt.ylabel('MSE') plt.title('PLS') plt.xlim(xmin=-1) plt.show() # Run PLS with suggested number of components pls = PLSRegression(n_components=msemin+1) pls.fit(X_calib, Y_calib) Y_pred = pls.predict(X_valid) # Calculate and print scores score_p = r2_score(Y_valid, Y_pred) mse_p = mean_squared_error(Y_valid, Y_pred) sep = np.std(Y_pred[:,0]-Y_valid) rpd = np.std(Y_valid)/sep bias = np.mean(Y_pred[:,0]-Y_valid) print('R2: %5.3f' % score_p)
my_salary = df['salary'] > 60000 df[df['salary'] > 60000] or df[my_salary] df.as_matrix() #returns numpy array. #Data Visualization Reference. import numpy as np import pandas as pd import matplotlib.pylot as plt %matplotlib inline #jupyter notebook only. below line for everything else. plt.show() x = np.arange(0, 10) y = x ** 2 plt.plot(x, y, 'red') #shows red line. plt.plot(x, y, '*') #shows stars on graph. plt.plot(x, y, 'r--') #shows red line with dashes. plt.xlim(0, 4) #shows x-axis limits at 0 and 4. plt.ylim(0, 10) #shows y-axis limits at 0 and 10. plt.title("title goes here") plt.xlabel('x label goes here') plt.ylabel('y label goes here') mat = np.arange(0, 100).reshape(10, 10) #makes array. plt.imshow(mat, cmap = 'RdYlGn') mat = np.random.randint(0, 1000, (10, 10)) plt.imshow(mat) plt.colorbar() df = pd.read_csv('salaries.csv') df.plot(x = 'salary', y = 'age', kind = 'scatter') #kind could be 'line' or whatever else you need. #SciKit-Learn Reference/Pre-Processing. import numpy as np from sklearn.preprocessing import MinMaxScaler
#Rafael Almeida # K-MEANS import pandas as pd import numpy as np import matplotlib.pylot as plt %matplotlib inline df = pd.DataFrame({ 'x': [12, 20, 28, 18, 29, 33, 24, 45, 45, 52, 51, 52, 55, 53, 55, 61, 64, 69, 72], 'y': [39, 36, 30, 52, 54, 46, 55, 59, 63, 70, 66, 63, 58, 23, 14, 8, 19, 7, 24] }) np.random.seed(200) k = 3 # centroids[i] = [x,y] centroids = { i +1 [np.random.randint(0, 80), np.random.randint(0, 80)] for i in range (k) } fig = plt.figure(figsize = (5,5)) plt.scatter(df['x'], df['y'], color= 'k') colmap = {1: 'r', 2: 'g', 3: 'b'} for i in centroids.keys(): plt.scatter(*centroids[i], color=colmap[i]) plt.xlim(0, 80) plt.ylim(0, 80) plt.show()