<jupyter_start><jupyter_text>Iris Project  Data Exploration and Analysis<jupyter_code>import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(color_codes= True)
%matplotlib inline

df = pd.read_csv('iris.data')
df.head()
# To know about pd.read_csv
pd.read_csv?
# Previously we were getting 1st data as header
# To remove this we can use header= None
df = pd.read_csv('iris.data', header=None) 
# Now we can see our data
df.head()
column_name = ['sepal length', 'sepal width', 'petal length', 'petal width', 'class']
# Assigning column name
df.columns = column_name
df.head()<jupyter_output><empty_output><jupyter_text>Iris dataset with seaborn<jupyter_code>iris = sns.load_dataset('iris')
iris.head()
# Describe using pandas dataframe
df.describe()
# Describe with seaborn
iris.describe()
print(df.info())
print(iris.info())
# We can visualize data by a specific group
print(iris.groupby('species').size())
# We can specify the number of data we want to see, here first 10 
df.head(10)
# It will print the last 5 data
df.tail()
# last 17 data 
df.tail(17)
# We can visualize data by a specific group, here by sepal length
print(iris.groupby('sepal_length').size())<jupyter_output>sepal_length
4.3     1
4.4     3
4.5     1
4.6     4
4.7     2
4.8     5
4.9     6
5.0    10
5.1     9
5.2     4
5.3     1
5.4     6
5.5     7
5.6     6
5.7     8
5.8     7
5.9     3
6.0     6
6.1     6
6.2     4
6.3     9
6.4     7
6.5     5
6.6     2
6.7     8
6.8     3
6.9     4
7.0     1
7.1     1
7.2     3
7.3     1
7.4     1
7.6     1
7.7     4
7.9     1
dtype: int64<jupyter_text>Visualization<jupyter_code>sns.pairplot(iris, hue = 'species', size=1.5)
sns.pairplot(iris, hue = 'species', size=3, aspect= 1)
sns.pairplot(iris, hue = 'species', diag_kind= 'hist', size=3, aspect= 1)
# plotting the histogram for iris dataset
iris.hist(edgecolor= 'orange', linewidth= 1.2, figsize= (10,6));
#iris.hist?
# Violin plot

plt.figure(figsize= (12, 8))  # declaring the figure size
plt.subplot(2,2,1)
sns.violinplot(x = 'species',y= 'sepal_length', data= iris)
plt.subplot(2,2,2)
sns.violinplot(x= 'species', y= 'sepal_width', data= iris)
plt.subplot(2,2,3)
sns.violinplot(x= 'species', y= 'petal_length', data= iris)
plt.subplot(2,2,4)
sns.violinplot(x= 'species', y= 'petal_width', data= iris)
# Box plot
iris.boxplot(by= 'species', figsize= (12,8));
pd.plotting.scatter_matrix(iris, figsize=(12,8))
plt.show()<jupyter_output><empty_output><jupyter_text>Working with Scikit-Learn  Simple Linear Regression using supervised learning<jupyter_code># generating feature matrix
x = 7 * np.random.rand(150)
print(x.shape)
print(x[12])
print(x.max())
# generating target values
y = 5*x + np.random.randn(150)       # randn used for normally distibuted data
print(y.shape)
print(y[33])
# scatter plot to visualize our generated data
plt.scatter(x,y)
plt.show()
#importing linear regression model from scikit-learn
from sklearn.linear_model import LinearRegression 
# taking linear regression as our model
model = LinearRegression(fit_intercept= True)
print(model)
# reshaping our feature x as matrix form (here it will be a column matrix)
X = x.reshape(-1, 1)
print(X.shape)
# Fitting our data to the model
model.fit(X, y)
# getting the coefficent of this model (slope)
model.coef_
# we got co efficent 1.931 which is close enough to our given coefficient 2
#  Now we will look up into the interception 
model.intercept_
# Perform prediction on unknown data
x_fit = np.linspace(-1, 11)
print(len(x_fit))
print(x_fit)
# reshaping to matrix format 
X_fit = x_fit.reshape(-1, 1)
print(len(X_fit))
# fit the model with X_fit(unknown data)
y_fit = model.predict(X_fit)
print(y_fit)
# plotting the scatter diagram 
plt.scatter(x,y)         # for the data x & y
plt.plot(x_fit, y_fit)   # for the linear line which predicted by our model 
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12175699974312869, 'fraction_numerical': 0.04469560750064218, 'mean_word_length': 3.998716302952503, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '323746', 'license': 'MIT', 'n_tokens_mistral': 1577, 'n_tokens_neox': 1498, 'n_words': 453, 'path': 'Iris_project/Iris_Project.ipynb', 'repo_name': 'taareek/machine_learning', 'size': '3893'}