<jupyter_start><jupyter_text><jupyter_code>import pandas as pd
import numpy as np
persons = pd.read_csv('https://raw.githubusercontent.com/LambdaSchool/DS-Unit-1-Sprint-1-Dealing-With-Data/master/module4-databackedassertions/persons.csv',header=None)
persons.head()
persons.describe()<jupyter_output><empty_output><jupyter_text>1. What are the variable types in the data?<jupyter_code>persons.dtypes
converted_persons = persons.convert_objects(convert_numeric=True)
converted_persons.head()
converted_persons .convert_objects(convert_numeric=True).dtypes
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv('https://raw.githubusercontent.com/LambdaSchool/DS-Unit-1-Sprint-1-Dealing-With-Data/master/module4-databackedassertions/persons.csv', index_col=0)
corr = data.corr()
fig = plt.figure()
ax = fig.add_subplot(111)
cax = ax.matshow(corr,cmap='coolwarm', vmin=-1, vmax=1)
fig.colorbar(cax)
ticks = np.arange(0,len(data.columns),1)
ax.set_xticks(ticks)
plt.xticks(rotation=90)
ax.set_yticks(ticks)
ax.set_xticklabels(data.columns)
ax.set_yticklabels(data.columns)
plt.show()<jupyter_output><empty_output><jupyter_text>2. What are the relationships between the variables? Age is correllated with weight as shown above in graph.<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
from sklearn import datasets
from sklearn.decomposition import PCA
import pandas as pd
from sklearn.preprocessing import StandardScaler


#splitting the dataset into the source variables (independant variables) and the target variable (dependant variable)
data = persons.iloc[:,:-1] #all columns except the last one
target = persons.iloc[:,len(persons.iloc[0])-1] #only the last column
X = data
y = target
#In general a good idea is to scale the data
scaler = StandardScaler()
scaler.fit(X)
X=scaler.transform(X)    

pca = PCA()
x_new = pca.fit_transform(X)

def myplot(score,coeff,labels=None):
    xs = score[:,0]
    ys = score[:,1]
    n = coeff.shape[0]
    scalex = 1.0/(xs.max() - xs.min())
    scaley = 1.0/(ys.max() - ys.min())
    plt.scatter(xs * scalex,ys * scaley, c = y)
    for i in range(n):
        plt.arrow(0, 0, coeff[i,0], coeff[i,1],color = 'r',alpha = 0.5)
        if labels is None:
            plt.text(coeff[i,0]* 1.15, coeff[i,1] * 1.15, "Var"+str(i+1), color = 'g', ha = 'center', va = 'center')
        else:
            plt.text(coeff[i,0]* 1.15, coeff[i,1] * 1.15, labels[i], color = 'g', ha = 'center', va = 'center')
plt.xlim(-1,1)
plt.ylim(-1,1)
plt.xlabel("PC{}".format(1))
plt.ylabel("PC{}".format(2))
plt.grid()

#Call the function. Use only the 2 PCs.
myplot(x_new[:,0:2],np.transpose(pca.components_[0:2, :]))
plt.show()<jupyter_output><empty_output><jupyter_text>3. Which relationships are "real", and which spurious?<jupyter_code><jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14860571831980232, 'fraction_numerical': 0.02223791034239322, 'mean_word_length': 5.160869565217391, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 2, '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': '319100', 'license': 'MIT', 'n_tokens_mistral': 1094, 'n_tokens_neox': 1061, 'n_words': 228, 'path': 'Lily_Su_Assignment4_LS_DS3_114_Making_Data_backed_Assertions.ipynb', 'repo_name': 'LilySu/DS-Unit-1-Sprint-1-Dealing-With-Data', 'size': '2833'}