Notes
Notes - notes.io |
# 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
import warnings
warnings.filterwarnings("ignore")
import re
from openpyxl import load_workbook
from datetime import datetime
# ------- AYPE Models --------------------
# 1- AYPE MS Prediction Model
# Data Çekme kodu ile değişecek
df_org = pd.read_excel("AYPE_Data_08082022.xlsx",index_col = 0,engine='openpyxl')
df_org.rename(columns = {'1201.1FI2_0210.DACA.PV':'AYPE1_Etilen_Capacity',
'1201.2FI2_0210.DACA.PV':'AYPE2_Etilen_Capacity',
'1201.0FI5_0902.DACA.PV':'AYPE_MS_Import',
'5801.11MBL01CT001_XQ60':'Ambient_Temperature',
'1201.1PIC1_0243.DACA.PV':'AYPE1_Reaktor_Basinci',
'1201.2PIC1_0243.DACA.PV':'AYPE2_Reaktor_Basinci',
'1201.0FI5_0901.DACA.PV': 'AYPE_HS_Import',
'1201.0FI5_0903.DACA.PV': 'AYPE_LS_Import'}, inplace = True)
df_aype = copy.deepcopy(df_org)
# Confidence 0 olan dataları veri setinden düşürmek.
df_aype_manipulated = copy.deepcopy(df_aype)
confidence_cols = list([col for col in df_aype_manipulated.columns if 'Confidence' in col])
for i in confidence_cols:
df_aype_manipulated.drop(
df_aype_manipulated.loc[(df_aype_manipulated[i] == 0)].index,
inplace=True)
df_aype_manipulated.drop(confidence_cols,axis=1,inplace=True)
# Sıfırdan küçük değerlerin sıfıra eşitlenmesi
main_features = list(df_aype_manipulated.columns)
main_features.remove('Ambient_Temperature')
for i in main_features:
df_aype_manipulated.loc[df_aype_manipulated[i] < 0, i] = 0
df_aype_manipulated.loc[df_aype_manipulated['Ambient_Temperature']<=-10,'Ambient_Temperature'] = -10
# Reaktör basıncı durumuna göre kapasite değerlerinin düzenlenmesi
df_aype_manipulated.loc[df_aype_manipulated['AYPE1_Reaktor_Basinci']<=1000,'AYPE1_Etilen_Capacity'] = 0
df_aype_manipulated.loc[df_aype_manipulated['AYPE2_Reaktor_Basinci']<=1000,'AYPE2_Etilen_Capacity'] = 0
df_aype_manipulated.drop(df_aype_manipulated.loc[(df_aype_manipulated['AYPE1_Reaktor_Basinci'] <=1000) & (df_aype_manipulated['AYPE1_Etilen_Capacity'] <= 9000)].index,inplace=True)
df_aype_manipulated.drop(df_aype_manipulated.loc[(df_aype_manipulated['AYPE2_Reaktor_Basinci'] <=1000) & (df_aype_manipulated['AYPE2_Etilen_Capacity'] <= 9000)].index,inplace=True)
# Ek feature'lar eklenmesi
df_aype_manipulated['Total_capacity_kg/h'] = df_aype_manipulated['AYPE1_Etilen_Capacity'] + df_aype_manipulated['AYPE2_Etilen_Capacity']
target_aype_ms_import_model = 'AYPE_MS_Import'
df_aype_manipulated.drop(df_aype_manipulated.loc[((df_aype_manipulated['Total_capacity_kg/h'] >=20000) & (df_aype_manipulated[target_aype_ms_import_model] <=4.5))].index,inplace=True)
print(df_aype_manipulated)
# Model datasının hazırlanması (kullanılmayacak feature'lar çıkarılmalı)
df_aype_ms_import_model = df_aype_manipulated[['AYPE1_Etilen_Capacity', 'AYPE2_Etilen_Capacity',
'AYPE_MS_Import','Ambient_Temperature','Total_capacity_kg/h']]
df_aype_ms_import_model = df_aype_ms_import_model.dropna()
# Model kodları
df_aype_ms_import_model_df = df_aype_ms_import_model[['AYPE1_Etilen_Capacity','AYPE2_Etilen_Capacity','AYPE_MS_Import']]
# Model Pipeline with GridSearchCV
result_aype_ms_prediction = best_model_pipeline(n=100,df=df_aype_ms_import_model_df,target=target_aype_ms_import_model,name_of_model='AYPE_MS_Import_Model')
# Model sonuçları Excel'e yazılıyor.
n = (len(result_aype_ms_prediction) - 2)/2
model_pred_aype_ms_import_model = round(result_aype_ms_prediction[0], 2)
model_intercept_aype_ms_import_model = round(result_aype_ms_prediction[1], 2)
values_used_in_aype_ms_import_model = [round(num, 2) for num in result_aype_ms_prediction[int(-n):]]
model_coefs_of_aype_ms_import_model = [round(num, 2) for num in result_aype_ms_prediction[2:int(2+n)]]
# Arom FG Prediction Model Sonuçları Excel'e yazılıyor.
wb = load_workbook('Draft_Final_Output.xlsx')
main_summary_sheet = wb['Main_Summary_Sheet']
main_summary_sheet['D9'] = values_used_in_aype_ms_import_model[0]
main_summary_sheet['D10'] = values_used_in_aype_ms_import_model[1]
aype_sheet = wb['AYPE']
aype_sheet['B3'] = values_used_in_aype_ms_import_model[0]
aype_sheet['B4'] = values_used_in_aype_ms_import_model[1]
aype_sheet['D3'] = model_coefs_of_aype_ms_import_model[0]
aype_sheet['D4'] = model_coefs_of_aype_ms_import_model[1]
aype_sheet['B5'] = model_intercept_aype_ms_import_model
aype_sheet['L2'] = model_pred_aype_ms_import_model
aype_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()
|
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