VaneshDev commited on
Commit
b2762d2
·
verified ·
1 Parent(s): 612bace

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -15
app.py CHANGED
@@ -3,43 +3,63 @@ import pandas as pd
3
  import numpy as np
4
  from sklearn.linear_model import LogisticRegression
5
  from sklearn.model_selection import train_test_split
 
6
  import matplotlib.pyplot as plt
7
- import statsmodels.api as sm
8
- from fbprophet import Prophet
9
 
10
- # Sample data (replace with your own usage/maintenance data)
11
  data = {
12
  'equipment_id': ['Excavator', 'Crane', 'Tractor'],
13
  'usage_hours': [120, 140, 100],
14
  'idle_hours': [30, 20, 50],
15
  'movement_frequency': [5, 7, 3],
16
- 'cost_per_hour': [10, 15, 12]
17
  }
18
 
19
- # Convert to DataFrame
20
  df = pd.DataFrame(data)
21
 
22
- # Function to make predictions (Logistic Regression)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  def model_prediction(equipment_id, usage_hours, idle_hours, movement_frequency, cost_per_hour):
24
- # Model input
25
  features = np.array([usage_hours, idle_hours, movement_frequency, cost_per_hour]).reshape(1, -1)
26
 
27
- # Train a simple logistic regression model (replace with your own trained model)
28
  model = LogisticRegression()
 
 
29
  X = df[['usage_hours', 'idle_hours', 'movement_frequency', 'cost_per_hour']]
30
- y = [0, 1, 0] # Dummy labels (0 = Repair, 1 = Move)
31
  model.fit(X, y)
32
-
33
- # Predict the suggestion
34
  prediction = model.predict(features)[0]
35
-
36
- # Define the suggestions
37
  suggestions = {0: 'Repair', 1: 'Move'}
38
 
39
- # Get confidence score
40
  confidence = model.predict_proba(features)[0][prediction] * 100
41
 
42
- # Return the result
43
  return f"Suggestion: {suggestions[prediction]}\nConfidence: {confidence:.2f}%"
44
 
45
  # Gradio Interface
 
3
  import numpy as np
4
  from sklearn.linear_model import LogisticRegression
5
  from sklearn.model_selection import train_test_split
6
+ from statsmodels.tsa.arima.model import ARIMA
7
  import matplotlib.pyplot as plt
 
 
8
 
9
+ # Sample data (this would be replaced with real equipment usage/maintenance data)
10
  data = {
11
  'equipment_id': ['Excavator', 'Crane', 'Tractor'],
12
  'usage_hours': [120, 140, 100],
13
  'idle_hours': [30, 20, 50],
14
  'movement_frequency': [5, 7, 3],
15
+ 'cost_per_hour': [10, 15, 12],
16
  }
17
 
18
+ # Convert data to DataFrame
19
  df = pd.DataFrame(data)
20
 
21
+ # Function to perform Time Series Analysis (using ARIMA)
22
+ def time_series_analysis(equipment_id, usage_hours):
23
+ # Simulate time series data (here using random data for demonstration)
24
+ dates = pd.date_range('2025-01-01', periods=10, freq='D')
25
+ usage_data = np.random.randint(100, 200, size=10) # Dummy usage data
26
+
27
+ # Create a DataFrame for time series data
28
+ ts_df = pd.DataFrame({'ds': dates, 'usage': usage_data})
29
+
30
+ # Fit ARIMA model (for simplicity, we use ARIMA(1,1,1) here)
31
+ model = ARIMA(ts_df['usage'], order=(1, 1, 1))
32
+ model_fit = model.fit()
33
+
34
+ # Forecast the next value (predict the future usage)
35
+ forecast = model_fit.forecast(steps=1)
36
+
37
+ # Return forecasted value
38
+ return f"Forecasted usage for the next day: {forecast[0]:.2f}"
39
+
40
+ # Logistic Regression model (using usage and idle hours to predict equipment status)
41
  def model_prediction(equipment_id, usage_hours, idle_hours, movement_frequency, cost_per_hour):
42
+ # Feature extraction (from usage data)
43
  features = np.array([usage_hours, idle_hours, movement_frequency, cost_per_hour]).reshape(1, -1)
44
 
45
+ # Logistic Regression model (this is an example, replace with your trained model)
46
  model = LogisticRegression()
47
+
48
+ # Train on dummy data (replace this with historical usage data for actual training)
49
  X = df[['usage_hours', 'idle_hours', 'movement_frequency', 'cost_per_hour']]
50
+ y = [0, 1, 0] # 0 = Repair, 1 = Move (example)
51
  model.fit(X, y)
52
+
53
+ # Predict suggestion (0 = Repair, 1 = Move)
54
  prediction = model.predict(features)[0]
55
+
56
+ # Define suggestions
57
  suggestions = {0: 'Repair', 1: 'Move'}
58
 
59
+ # Confidence score (example)
60
  confidence = model.predict_proba(features)[0][prediction] * 100
61
 
62
+ # Return the suggestion and confidence
63
  return f"Suggestion: {suggestions[prediction]}\nConfidence: {confidence:.2f}%"
64
 
65
  # Gradio Interface