<jupyter_start><jupyter_text>Training And Testing Available Data We have a dataset containing prices of used BMW cars. We are going to analyze this datasetand build a prediction function that can predict a price by taking mileage and age of the caras input. We will use sklearn train_test_split method to split training and testing dataset<jupyter_code>import pandas as pd
df = pd.read_csv("carprices.csv")
df.head()
import matplotlib.pyplot as plt
%matplotlib inline<jupyter_output><empty_output><jupyter_text>**Car Mileage Vs Sell Price ($)**<jupyter_code>plt.scatter(df['Mileage'],df['Sell Price($)'])<jupyter_output><empty_output><jupyter_text>**Car Age Vs Sell Price ($)**<jupyter_code>plt.scatter(df['Age(yrs)'],df['Sell Price($)'])<jupyter_output><empty_output><jupyter_text>**Looking at above two scatter plots, using linear regression model makes sense as we can clearly see a linear relationship between our dependant (i.e. Sell Price) and independant variables (i.e. car age and car mileage)** The approach we are going to use here is to split available data in two sets                    Training: We will train our model on this dataset        Testing: We will use this subset to make actual predictions using trained model             The reason we don't use same training set for testing is because our model has seen those samples before, using same samples for making predictions might give us wrong impression about accuracy of our model. It is like you ask same questions in exam paper as you tought the students in the class.<jupyter_code>X = df[['Mileage','Age(yrs)']]
y = df['Sell Price($)']
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.3) 
X_train
X_test
y_train
y_test<jupyter_output><empty_output><jupyter_text>**Lets run linear regression model now**<jupyter_code>from sklearn.linear_model import LinearRegression
clf = LinearRegression()
clf.fit(X_train, y_train)
X_test
clf.predict(X_test)
y_test
clf.score(X_test, y_test)<jupyter_output><empty_output><jupyter_text>**random_state argument**<jupyter_code>X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.3,random_state=10)
X_test<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08732646663681147, 'fraction_numerical': 0.0026869682042095834, 'mean_word_length': 6.276872964169381, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '520951', 'license': 'MIT', 'n_tokens_mistral': 721, 'n_tokens_neox': 699, 'n_words': 241, 'path': "Program's_Contributed_By_Contributors/AI-Summer-Course/py-master/ML/6_train_test_split/train_test_split.ipynb", 'repo_name': 'siddharthdeo99/Hacktoberfest2k21', 'size': '2233'}