Basic line plot%matplotlib notebook -- to create visualization in jupyter notebookimport matplotlib.pyplot as pltimport numpy as npX = np.arange(10)plt.plot(X)Create figure and Plot in two lines1. Create Figurefig = plt.figure()2. Create Plot and add plot to figureax1 = fig.add_subplot(2,2,1) --- 2 rows, 2 column and we are selecting...
Friday, 7 October 2022
Thursday, 6 October 2022
1. Python Machine learning - Regularized Linear Model
Linear Regressionfrom sklearn.linear_model import LinearRegression lin_reg = LinearRegression()lin_reg.fit(X, y)print(lin_reg.intercept_, lin_reg.coef_)lin_reg.predict(X_new)Polynomial RegressionTransform to polynomial featurefrom sklearn.preprocessing import PolynomialFeaturespoly_features = PolynomialFeatures(degree =2, include_bias=False)X_poly...
Tuesday, 4 October 2022
7. Data Analysis - Data Aggregation & Grouping
Split, Apply, CombineMeanX["Values1"].groupby([X["Keys1"]]).mean() -- Mean of "Values1" based on Keys = "Key1"X["Values1"].groupby([X["Keys1"],X["Keys2"]]).mean()X.groupBy["Keys1"].mean()X.groupBy(X["Keys1"], X["Keys2"]).mean()CountX.groupBy(X["Keys1"], X["Keys2"]).size()GroupBy Clause with FOR Loopfor name, group in X.groupby([["Key1"]])print...
6. Data Analysis - Data Wrangling
Hierarchical Indexing in Pandas SeriesCreate multi level indexing in pandas seriespd.Series(np.random.rand(9), index=[['a','b','c','d','a','b','c','d','a'],[1,2,4,4,5,2,7,8,8]],)Access the valuesX['a'] -- using exact indexX[:, 1] -- using sliceX['a':'b', 1] -- using sliceAccess IndexX.index -- return tupleChanging multi level...