import pandas as pd import numpy as np import streamlit as st import joblib from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense, Dropout, BatchNormalization from tensorflow.keras.callbacks import EarlyStopping from sklearn.preprocessing import MinMaxScaler from sklearn.model_selection import train_test_split from sklearn.metrics import r2_score,mean_squared_error from sklearn.compose import ColumnTransformer # Load data df = pd.read_csv('train.csv') # Convert timestamp to datetime and extract features df['timestamp'] = pd.to_datetime(df['timestamp']) df['year'] = df['timestamp'].dt.year df['month'] = df['timestamp'].dt.month df['day'] = df['timestamp'].dt.day df['hour'] = df['timestamp'].dt.hour df['minute'] = df['timestamp'].dt.minute # Drop the original timestamp and keep only numeric columns for features x = df.drop(['x', 'timestamp'], axis=1) # Drop unused columns y = df[['x']] # Ensure all columns in x are numeric x = x.select_dtypes(include=[np.number]) # Select only numeric columns # Train-test split x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.20, random_state=42) # Preprocessor for numerical data preprocessor = MinMaxScaler() # Prediction function for new data def time_pred(y, year, month, day, hour, minute): input_data = pd.DataFrame({ 'y': [y], 'year': [year], 'month': [month], 'day': [day], 'hour': [hour], 'minute': [minute] }) input_data_transformed = preprocessor.fit_transform(input_data) model = joblib.load('Tek.pkl') prediction = model.predict(input_data_transformed) return float(prediction[0]) st.write("Veri Gir") y = st.selectbox('y', df['y'].unique()) year = st.number_input('Year', min_value=1900, max_value=2100, value=1900) month = st.number_input('Month', min_value=1, max_value=12, value=1) day = st.number_input('Day', min_value=1, max_value=31, value=1) hour = st.number_input('Hour', min_value=0, max_value=23, value=0) minute = st.number_input('Minute', min_value=0, max_value=59, value=0) if st.button('Predict'): time = time_pred(y, year, month, day, hour, minute) st.write(f'The predicted time is: {time:.2f}')