<jupyter_start><jupyter_text><jupyter_code>cd /home

from xlrd import open_workbook
import csv
wb = open_workbook('problem_statement.xlsx')
for i in range(wb.nsheets):
    sheet = wb.sheet_by_index(i)
    print(sheet.name)
    with open("%s.csv" %(sheet.name.replace(" ","")), "w") as file:
        writer = csv.writer(file, delimiter = ",")
        print(sheet, sheet.name, sheet.ncols, sheet.nrows)
        header = [cell.value for cell in sheet.row(0)]
        writer.writerow(header)
        for row_idx in range(1, sheet.nrows):
            row = [int(cell.value) if isinstance(cell.value, float) else cell.value
                   for cell in sheet.row(row_idx)]
            writer.writerow(row)
import pandas as pd
import numpy as np<jupyter_output><empty_output><jupyter_text>Now take 5th data for training purpose<jupyter_code>df = pd.read_csv('Credit_card_fraud_linear_5.csv')
print(df.shape)
df.head(10)
df.describe()
list(df['$_Surcharge_Levied'])
df.isnull().sum()
df['Customer_Type'].unique()
pd.get_dummies(df['Customer_Type']).head()
df = pd.get_dummies(df, columns=['Customer_Type'])
df.head()
print(df.shape)
print(df.ndim)  
df.info()
X  = df.drop('$_Surcharge_Levied', axis=1)
print(X.shape)
X.head()

Y = df['$_Surcharge_Levied']
print(Y.shape)
Y.head()
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.33, random_state=42)

from sklearn import preprocessing
y_train_norm = preprocessing.normalize(np.array(y_train).reshape(-1, 1))
y_train_norm[:10]

from sklearn import preprocessing
y_norm = preprocessing.normalize(np.array(y_test).reshape(-1, 1))
y_norm[:10]
import os
import pandas as pd
from pandas import DataFrame,Series
from sklearn import tree
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
from sklearn import svm
from sklearn.preprocessing import StandardScaler
import statsmodels.formula.api as smf
import statsmodels.api as sm
from mpl_toolkits.mplot3d import Axes3D
import seaborn as sns
from sklearn import neighbors
from sklearn import linear_model
%matplotlib inline
dec = tree.DecisionTreeRegressor(max_depth=1)
dec.fit(X_train, y_train)<jupyter_output><empty_output><jupyter_text>**although the smaller the RMSE, the better result/accuracy**<jupyter_code>from sklearn import metrics 
dec_pred = dec.predict(X_test)
print(metrics.mean_squared_error(y_test , dec_pred))
print(metrics.r2_score(y_test , dec_pred))
# fit a model
lm = linear_model.LinearRegression()
li = lm.fit(X_train, y_train)
li_pred = li.predict(X_test)
print(metrics.mean_squared_error(y_test , li_pred))

from sklearn.ensemble import RandomForestRegressor
reg = RandomForestRegressor()
reg.fit(X_train,y_train)
ran_pred = reg.predict(X_test)
print(metrics.mean_squared_error(y_test , ran_pred))

import xgboost as xgb
from sklearn.metrics import mean_squared_error
xg_reg = xgb.XGBRegressor(objective ='reg:linear', colsample_bytree = 0.3, learning_rate = 0.1, max_depth = 5, alpha = 10, n_estimators = 10)
xg_reg.fit(X_train,y_train)
xgb_preds = xg_reg.predict(X_test)
print(metrics.mean_squared_error(y_test , xgb_preds))
from xlrd import open_workbook
import csv
wb = open_workbook('Prediction_data.xlsx')
for i in range(wb.nsheets):
    sheet = wb.sheet_by_index(i)
    print(sheet.name)
    with open("%s.csv" %(sheet.name.replace(" ","")), "w") as file:
        writer = csv.writer(file, delimiter = ",")
        print(sheet, sheet.name, sheet.ncols, sheet.nrows)
        header = [cell.value for cell in sheet.row(0)]
        writer.writerow(header)
        for row_idx in range(1, sheet.nrows):
            row = [int(cell.value) if isinstance(cell.value, float) else cell.value
                   for cell in sheet.row(row_idx)]
            writer.writerow(row)
test_df = pd.read_csv('Prediction_Data.csv')
print(test_df.shape)
test_df.head(10)
test_df.info()
test_df = pd.get_dummies(test_df, columns=['Customer_Type'])
test_df.head()
print(test_df.shape)
X_dftest  = test_df.drop('$_Surcharge_Levied', axis=1)
print(X_dftest.shape)
X_dftest.head()

from sklearn import preprocessing
y_out = preprocessing.normalize(np.array(Y).reshape(-1, 1))
y_out[:10]<jupyter_output><empty_output><jupyter_text>**E+01 means moving the decimal point one digit to the right, E+00 means leaving the decimal point where it is, and E–01 means moving the decimal point one digit to the left.**<jupyter_code>print(Output.shape)
Output
leived_val = list(output)
# dec_out , random_out, output, Output
new = pd.DataFrame(list(Output))
new.describe()

mean = 0.344815
std = 0.749592
n= []
for i in list(Output):
  n.append(((i-mean)/std)*100)
new['1'] = n
new.head(10)


leived_val = list(output)
test_df['$_Surcharge_Levied'] = leived_val
print(test_df.shape)
test_df.head(10)
test_df.to_csv('prediction_output.csv' , index = False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12417627677100494, 'fraction_numerical': 0.014415156507413509, 'mean_word_length': 5.24293059125964, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '326452', 'license': 'MIT', 'n_tokens_mistral': 1842, 'n_tokens_neox': 1774, 'n_words': 385, 'path': 'Regression_Problem_find_SurchargeLevyValue.ipynb', 'repo_name': 'Rupak7/Machine_learning', 'size': '4856'}