<jupyter_start><jupyter_text>Nino-Palm 종가 파일 만들기<jupyter_code>nino34_df = pd.read_excel('PALMOIL_NINO.xlsx', sheet_name = 'Nino3.4')
nino34_df.head()
list(nino34_df.columns.values)[1:]
nino34 = pd.melt(nino34_df, id_vars=['year'], value_vars=list(nino34_df.columns.values)[1:], var_name='month', value_name='nino34')
nino34.head()
nino34['DATE'] = pd.to_datetime(nino34[['year', 'month']].assign(DAY=1))
nino34.sort_values(by='DATE', inplace=True)
nino34.head()
palm = pd.read_csv('원유 팜유 선물 내역.csv')
palm.head()
palm['YEAR'] = palm['YEAR'].str.rstrip('년')
palm['MONTH'] = palm['MONTH'].str.rstrip('월')
palm
palm['DATE'] = pd.to_datetime(palm[['YEAR', 'MONTH']].assign(DAY=1))
palm.head()
df = palm.merge(nino34, how='inner', on='DATE')
df.sort_values(by='DATE', inplace=True)
df.head()
df['종가'] = pd.to_numeric(df['종가'])
df = df.drop(df[df.종가 <= 0].index)
df
def excel_writer(excel_path, dataframe):
    writer = pd.ExcelWriter(excel_path, engine='xlsxwriter')
    dataframe.to_excel(writer, index=False)
    writer.close()
excel_writer('palm_nino_concat.xlsx', df)<jupyter_output><empty_output><jupyter_text>테스트-correlation<jupyter_code>def cross_corr(x, y, lag):
    return x.corr(y.shift(periods=lag))
nino_palm = [cross_corr(df['nino34'], df['종가'], lag=i) for i in range(11)]
nino_palm
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
df.nino34.plot(ax=ax, style='r-')
df.종가.plot(ax=ax, style='b-', secondary_y=True)<jupyter_output><empty_output><jupyter_text>테스트-Random Forest Regression<jupyter_code>x = df[['nino34']]
y = df['종가']
from sklearn.ensemble import RandomForestRegressor
regressor = RandomForestRegressor()
regressor.fit(x, y)
y_pred = regressor.predict(np.array([6.5]).reshape(1, 1))
np.array([6.5]).reshape(1, 1)
X_grid = np.arange(min(df['nino34']), max(df['nino34']), 0.01)
X_grid = X_grid.reshape((len(X_grid), 1))
plt.scatter(x, y, color = 'b') 
plt.plot(X_grid, regressor.predict(X_grid),color = 'green')
plt.rcParams["figure.figsize"] = (15,5)
plt.title('Random Forest Regression')
plt.xlabel('Nino3.4')
plt.ylabel('Palm Oil')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20276059019514517, 'fraction_numerical': 0.029509757258448358, 'mean_word_length': 7.794979079497908, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 13, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '558460', 'license': 'MIT', 'n_tokens_mistral': 978, 'n_tokens_neox': 967, 'n_words': 128, 'path': 'Make_Nino-Palm_Dataset.ipynb', 'repo_name': 'Soo-Im/PalmOil', 'size': '2101'}