<jupyter_start><jupyter_text>Ex 1-1<jupyter_code>def prepare_country_stats(oecd_bli, gdp_per_capita):
    oecd_bli = oecd_bli[oecd_bli["INEQUALITY"] == "TOT"]
    oecd_bli = oecd_bli.pivot(index="Country", columns="Indicator", values="Value")
    
    gdp_per_capita.rename(columns={"2015": "GDP per capita"}, inplace=True)
    gdp_per_capita.set_index("Country", inplace=True)
    full_country_stats = pd.merge(left=oecd_bli, right=gdp_per_capita, left_index=True, right_index=True)
    full_country_stats.sort_values(by="GDP per capita", inplace=True)
    remove_indices = [0,1,6,8,33,34,35]
    keep_indices = list(set(range(36)) - set(remove_indices))
    return full_country_stats[["GDP per capita", 'Life satisfaction']].iloc[keep_indices]
        
datapath = os.path.join('datasets', 'lifesat', '')
datapath
oecd_bli = pd.read_csv(datapath + 'oecd_bli_2015.csv', thousands=',')
oecd_bli.describe()
oecd_bli.head()
oecd_bli.pivot(index="Country", columns="Indicator", values="Value")
oecd_bli['INEQUALITY'].describe()
oecd_bli['INEQUALITY'].unique()
inequality = oecd_bli[oecd_bli['INEQUALITY'].isin(['MN', 'WMN', 'HGH', 'LW'])].sort_values(by='Value')
inequality
gdp_per_capita = pd.read_csv(datapath + 'gdp_per_capita.csv', thousands=',', delimiter='\t', encoding='latin1', na_values='n/a')
gdp_per_capita.describe()
gdp_per_capita.head()
country_stats = prepare_country_stats(oecd_bli, gdp_per_capita)
country_stats
X = np.c_[country_stats['GDP per capita']]
y = np.c_[country_stats['Life satisfaction']]
country_stats['GDP per capita']
X
y
country_stats['Life satisfaction']
country_stats.plot(kind='scatter', x='GDP per capita', y='Life satisfaction')
plt.show()
model = sklearn.linear_model.LinearRegression()
model.fit(X, y)
X_new = [[22587]]
print(model.predict(X_new))<jupyter_output>[[5.96242338]]<jupyter_text>Some Pandas<jupyter_code>?pd.DataFrame.iloc<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1636842105263158, 'fraction_numerical': 0.019473684210526317, 'mean_word_length': 8.228155339805825, 'pattern_counts': {'":': 1, '<': 8, '<?xml version=': 0, '>': 8, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '127600', 'license': 'Apache-2.0', 'n_tokens_mistral': 802, 'n_tokens_neox': 769, 'n_words': 101, 'path': '01_.ipynb', 'repo_name': 'nikage/handson-ml', 'size': '1900'}