<jupyter_start><jupyter_text>Linear Regression Deep Learning<jupyter_code>import pandas as pd
import numpy as np
import logging
import math

import tensorflow as tf
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline

from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LinearRegression,Ridge,Lasso,ElasticNet
from sklearn.tree import DecisionTreeRegressor
from sklearn.metrics import mean_squared_error,r2_score
import statsmodels.formula.api as smf

import warnings
warnings.filterwarnings('ignore')
# constants
PROCESSED_DATA_DIR = '../data/processed/'
matched_trees_file_name = 'all_matched_trees.csv'
mtrees_columns =['stem_diameter', 'area', 'aerial_data_height', 'agb']

## Load matched trees dataset

matched_trees = pd.read_csv(PROCESSED_DATA_DIR+matched_trees_file_name, usecols=mtrees_columns)
matched_trees.head()
matched_trees.info()
matched_trees.isnull().sum()
matched_trees.describe()
plt.figure(figsize=(8,4))
sns.displot(matched_trees['agb'])
plt.figure(figsize=(12,8))
sns.scatterplot(x='agb',y='area',data=matched_trees)
plt.figure(figsize=(12,8))
sns.scatterplot(x='agb',y='aerial_data_height',data=matched_trees)
plt.figure(figsize=(12,8))
sns.scatterplot(x='agb',y='stem_diameter',data=matched_trees)
matched_trees.corr()
plt.figure(figsize=(10,8))
sns.heatmap(matched_trees.corr(), annot=True)<jupyter_output><empty_output><jupyter_text>Scaling and Train Test Split<jupyter_code>X = matched_trees.drop('agb',axis=1)
y = matched_trees['agb']

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,random_state=42)
X_train = X_train.reset_index(drop=True)
X_test = X_test.reset_index(drop=True)
from sklearn import preprocessing
scaler = preprocessing.StandardScaler().fit(X_train)
X_train_scaled = scaler.transform(X_train)
X_test_scaled = scaler.transform(X_test)


lrmodel = LinearRegression()
results = lrmodel.fit(X_train_scaled, y_train)
results.coef_
y_predict = lrmodel.predict(X_test_scaled)
print(lrmodel.intercept_, lrmodel.coef_)
print(math.sqrt(mean_squared_error(y_test, y_predict)))
print((r2_score(y_test,y_predict)))
print(lrmodel.score(X_test, y_test))



X_test.shape
y_test.shape
y_predict.shape<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11718408395277656, 'fraction_numerical': 0.009182334936598164, 'mean_word_length': 9.843601895734597, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '173841', 'license': 'MIT', 'n_tokens_mistral': 882, 'n_tokens_neox': 835, 'n_words': 133, 'path': 'notebooks/DeepLearningLinearRegression.ipynb', 'repo_name': 'jayhombal/forest-biomass-prediction', 'size': '2287'}