<jupyter_start><jupyter_text>Market Dataの分析  Pandasのインポート<jupyter_code>import pandas as pd
df=pd.read_csv("./Marketing_Data.csv")
df.head()
df.describe()
data=df.iloc[:,0:3].values
sales=df.iloc[:,3].values
import numpy as np
import matplotlib.pyplot as plt
label=["youtube","facebook","newspaper"]
for i in range(3):
    plt.figure(figsize=(3,3))
    plt.scatter(data[:,i],sales)
    plt.xlabel(label[i])
    plt.ylabel("SALES")
from sklearn.linear_model import LinearRegression
model = LinearRegression(normalize=True)# modelを作って
model.fit(data,sales)# fitする
#fit()には、(n行1列)の行列を入れる
print("coefficient:",model.coef_) # coeficient  y=ax+bのa
print("intercept:",model.intercept_) #intercept, 切片
print("R-square:",model.score(data,sales))
# score()で予測の良さを返します。linearRegression()のモデルではR^2値です
predicted=model.predict(data)# predict()で予測値を返します

plt.figure(figsize=(5,5))
plt.scatter(predicted,sales)
plt.xlabel("predicted sales")
plt.ylabel("actual sales")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1653061224489796, 'fraction_numerical': 0.01020408163265306, 'mean_word_length': 8.617647058823529, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '540482', 'license': 'MIT', 'n_tokens_mistral': 418, 'n_tokens_neox': 408, 'n_words': 54, 'path': 'src/assignment/201203/Market_Data_analysis.ipynb', 'repo_name': 'rosayjc/python_university', 'size': '980'}