NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

main_pp.py

# author : makcin

# Importing Libraries
import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.ensemble import RandomForestRegressor
import copy
from sklearn.metrics import mean_absolute_error
import openpyxl
from datetime import date, timedelta
from sklearn.linear_model import HuberRegressor, LinearRegression, TheilSenRegressor, RANSACRegressor
from sklearn.linear_model import Ridge, Lasso
from sklearn.model_selection import train_test_split, GridSearchCV
from sklearn.metrics import mean_squared_error, r2_score
from sklearn.linear_model import ElasticNetCV
from sklearn.linear_model import ElasticNet
from sklearn.utils.validation import check_consistent_length, check_array
pd.set_option('display.max_rows', 6000)
from scripts import _check_reg_targets,mean_absolute_percentage_error,best_model_pipeline,taking_average
import warnings
warnings.filterwarnings("ignore")
import re
from openpyxl import load_workbook
from datetime import datetime


# ------- PP Models --------------------
# 1- PP HS Import Model
# 2- PP LS Import Model
# 3- PP MS Import Model

# Data Çekme kodu ile değişecek

# 1- PP MS Import Model

df_org = pd.read_excel("PP_tags_08082022.xlsx",index_col = 0,engine='openpyxl')


df_org.rename(columns = {'1701.FI605':'Pp_HS_Import',
'1701.FI604':'Pp_MS_Import',
'1701.FI603':'Pp_LS_Import',
'5801.11MBL01CT001_XQ60':'Ambient_Temperature',
'2101.FT109A.DACA.PV':'Amonyak_capacity_kg/h',
'1701.IIH301A_L':'PP_Ekskruder1',
'1701.IIH301B_L':'PP_Ekskruder2',
'1701.FI201':'Propilen_capacity',
'1701.FI226':'PP_Fg'}, inplace = True)

df_pp = copy.deepcopy(df_org)

# Confidence 0 olan dataları veri setinden düşürmek.
df_pp_manipulated = copy.deepcopy(df_pp)

confidence_cols = list([col for col in df_pp_manipulated.columns if 'Confidence' in col])

for i in confidence_cols:
df_pp_manipulated.drop(
df_pp_manipulated.loc[(df_pp_manipulated[i] == 0)].index,
inplace=True)

df_pp_manipulated.drop(confidence_cols,axis=1,inplace=True)

# Sıfırdan küçük değerlerin sıfıra eşitlenmesi

main_features = list(df_pp_manipulated.columns)

main_features.remove('Ambient_Temperature')


for i in main_features:
df_pp_manipulated.loc[df_pp_manipulated[i] < 0, i] = 0

df_pp_manipulated.loc[df_pp_manipulated['Ambient_Temperature']<=-10,'Ambient_Temperature'] = -10

# Kapasitelere göre veride bazı düzenlemeler yapılması

df_pp_manipulated.loc[df_pp_manipulated['Propilen_capacity']>=18.5,'Propilen_capacity'] = 18.5

df_pp_manipulated.loc[df_pp_manipulated['Propilen_capacity']<=5,'Propilen_capacity'] = 0

df_pp_manipulated.loc[df_pp_manipulated['Propilen_capacity']<=5,'Pp_HS_Import'] = 0

target_pta_hs_import_model = 'PTA_HS_Import'

# Ekskruder durumunun veri temizliği

df_pp_manipulated.loc[df_pp_manipulated['PP_Ekskruder1']<=20,'PP_Ekskruder1'] = 0
df_pp_manipulated.loc[df_pp_manipulated['PP_Ekskruder2']<=20,'PP_Ekskruder2'] = 0

# Ekskruder on/off feature

df_pp_manipulated['Pp_Ekskruder1_on_off'] = 0
df_pp_manipulated['Pp_Ekskruder2_on_off'] = 0

df_pp_manipulated.loc[df_pp_manipulated['PP_Ekskruder1']>20,'Pp_Ekskruder1_on_off'] = 1
df_pp_manipulated.loc[df_pp_manipulated['PP_Ekskruder2']>20,'Pp_Ekskruder2_on_off'] = 1

df_pp_manipulated['Number_of_ekskruder_on'] = df_pp_manipulated['Pp_Ekskruder1_on_off'] + df_pp_manipulated['Pp_Ekskruder2_on_off']


# Model datasının hazırlanması (kullanılmayacak feature'lar çıkarılmalı)

df_pp_ms_import_model_df = df_pp_manipulated[['Number_of_ekskruder_on','Pp_Ekskruder1_on_off','Propilen_capacity','Pp_MS_Import']]

df_pp_ms_import_model_df = df_pp_ms_import_model_df.dropna()

target_pp_ms_import_model = 'Pp_MS_Import'

# Model kodları

# Model Pipeline with GridSearchCV

result_pp_ms_import_prediction = best_model_pipeline(n=1000,df=df_pp_ms_import_model_df,target=target_pp_ms_import_model,name_of_model='PP_MS_Import_Model')

# Model sonuçları Excel'e yazılıyor.

n = (len(result_pp_ms_import_prediction) - 2)/2

model_pred_pp_ms_import_model = round(result_pp_ms_import_prediction[0], 2)

model_intercept_pp_ms_import_model = round(result_pp_ms_import_prediction[1], 2)

values_used_in_pp_ms_import_model = [round(num, 2) for num in result_pp_ms_import_prediction[int(-n):]]

model_coefs_of_pp_ms_import_model = [round(num, 2) for num in result_pp_ms_import_prediction[2:int(2+n)]]


wb = load_workbook('Draft_Final_Output.xlsx')

main_summary_sheet = wb['Main_Summary_Sheet']

main_summary_sheet['D13'] = values_used_in_pp_ms_import_model[2]

pp_sheet = wb['PP']

pp_sheet['B3'] = values_used_in_pp_ms_import_model[0]

pp_sheet['B4'] = values_used_in_pp_ms_import_model[1]

pp_sheet['B5'] = values_used_in_pp_ms_import_model[2]


pp_sheet['D3'] = model_coefs_of_pp_ms_import_model[0]

pp_sheet['D4'] = model_coefs_of_pp_ms_import_model[1]

pp_sheet['D5'] = model_coefs_of_pp_ms_import_model[2]

pp_sheet['B6'] = model_intercept_pp_ms_import_model

pp_sheet['L2'] = model_pred_pp_ms_import_model

pp_sheet['R1'] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

# 2- PP LS Import Model

df_pp_ls_import_model_df = df_pp_manipulated[['Propilen_capacity', 'PP_Ekskruder2', 'Pp_LS_Import']]

target_pp_ls_import_model = "Pp_LS_Import"

# Model Pipeline with GridSearchCV

result_pp_ls_import_prediction = best_model_pipeline(n=1000,df=df_pp_ls_import_model_df,target=target_pp_ls_import_model,name_of_model='PP_LS_Import_Model')

# Model sonuçları Excel'e yazılıyor.

n = (len(result_pp_ls_import_prediction) - 2)/2

model_pred_pp_ls_import_model = round(result_pp_ls_import_prediction[0], 2)

model_intercept_pp_ls_import_model = round(result_pp_ls_import_prediction[1], 2)

values_used_in_pp_ls_import_model = [round(num, 2) for num in result_pp_ls_import_prediction[int(-n):]]

model_coefs_of_pp_ls_import_model = [round(num, 2) for num in result_pp_ls_import_prediction[2:int(2+n)]]

# Sonuclar Excel'e yazılıyor.

pp_sheet['B8'] = values_used_in_pp_ls_import_model[0]

pp_sheet['B9'] = values_used_in_pp_ls_import_model[1]

pp_sheet['D8'] = model_coefs_of_pp_ls_import_model[0]

pp_sheet['D9'] = model_coefs_of_pp_ls_import_model[1]

pp_sheet['B10'] = model_intercept_pp_ls_import_model

pp_sheet['L3'] = model_pred_pp_ls_import_model

pp_sheet['R1'] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

# 2- PP HS Import Model

df_pp_hs_import_model_df = df_pp_manipulated[['Propilen_capacity', 'Number_of_ekskruder_on', 'Pp_HS_Import']]

target_pp_hs_import_model = "Pp_HS_Import"

# Model Pipeline with GridSearchCV

result_pp_hs_import_prediction = best_model_pipeline(n=1000,df=df_pp_hs_import_model_df,target=target_pp_hs_import_model,name_of_model='PP_HS_Import_Model')

# Model sonuçları Excel'e yazılıyor.

n = (len(result_pp_hs_import_prediction) - 2)/2

model_pred_pp_hs_import_model = round(result_pp_hs_import_prediction[0], 2)

model_intercept_pp_hs_import_model = round(result_pp_hs_import_prediction[1], 2)

values_used_in_pp_hs_import_model = [round(num, 2) for num in result_pp_hs_import_prediction[int(-n):]]

model_coefs_of_pp_hs_import_model = [round(num, 2) for num in result_pp_hs_import_prediction[2:int(2+n)]]

# Arom FG Prediction Model Sonuçları Excel'e yazılıyor.

pp_sheet['D12'] = model_coefs_of_pp_hs_import_model[0]

pp_sheet['D13'] = model_coefs_of_pp_hs_import_model[1]

pp_sheet['B14'] = model_intercept_pp_ls_import_model

pp_sheet['L4'] = model_pred_pp_hs_import_model

pp_sheet['R1'] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

wb.save(r'C:Usersmert.akcinDesktopDaily NG DemandNG_Demand_NewNg_Demand_Prod_CodeDraft_Final_Output.xlsx')
wb.close()






     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.