0% found this document useful (0 votes)
8 views4 pages

A Training and Testing Model Is Developed Using The Provided Dataset in Jupyter Notebook 2

A training and testing model for predicting porosity is developed using a dataset in Jupyter Notebook with Python. The model employs a Random Forest regressor and evaluates performance using Mean-squared error and R² score, alongside a graphical representation of predicted versus actual porosity. Results are displayed in a tabulated format for comparison of actual and predicted values.

Uploaded by

u2007026
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

A Training and Testing Model Is Developed Using The Provided Dataset in Jupyter Notebook 2

A training and testing model for predicting porosity is developed using a dataset in Jupyter Notebook with Python. The model employs a Random Forest regressor and evaluates performance using Mean-squared error and R² score, alongside a graphical representation of predicted versus actual porosity. Results are displayed in a tabulated format for comparison of actual and predicted values.

Uploaded by

u2007026
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

• A training and testing model is developed using the provided dataset in Jupyter Notebook.

• The code is written using Python.


• The output shows the Mean-squared error, squared error, a graph showing predicted porosity
vs actual porosity, and tabulated actual porosity and predicted porosity.

import pandas as pd

import numpy as np

import matplotlib.pyplot as plt

from sklearn.model_selection import train_test_split

from sklearn.ensemble import RandomForestRegressor

from sklearn.metrics import mean_squared_error, r2_score

# Step 1: Load the dataset

data = {

"GR": [105.0241, 104.8832, 104.8206, 106.4206, 107.6301, 108.9435, 109.6038, 107.2867, 105.1824,
104.6506, 103.415, 103.6088, 102.9568, 101.7497, 100.2921, 100.4466, 101.3986, 103.812, 106.7401,
109.1152, 111.1988, 111.679, 111.6624, 111.5951, 109.7243, 110.051, 110.852, 110.4687, 110.2447,
107.1055, 101.623, 97.99983, 95.9412, 97.23185, 102.5178, 107.7495, 110.5326, 111.0461, 109.4907,
106.1861, 106.9531, 111.1288, 111.4157, 109.5503, 107.2062, 104.7279, 101.7846, 108.3299, 108.4753,
107.94, 106.8087, 104.5527, 103.6576, 103.0437, 102.9949, 104.8888, 104.5774, 103.0179, 102.1553,
99.7468, 97.26203, 96.04442, 96.14159, 96.32548, 97.28294, 99.04396, 101.5541, 105.0821, 106.9795,
109.1918, 109.0797, 106.7576, 102.948, 102.0777, 103.417, 106.9779, 109.3164, 114.2285, 113.186,
111.756, 110.9327, 111.5131, 110.7305, 110.4762],

"MXFL": [2.40768, 2.195605, 1.908103, 1.757668, 1.787998, 1.9264, 2.041258, 2.231793, 2.547698,
2.619671, 2.611392, 2.520982, 2.261424, 1.959945, 1.95817, 2.086364, 2.069686, 2.023673, 1.856997,
1.750725, 1.840206, 1.917097, 1.75794, 1.590595, 1.648303, 1.873707, 2.14548, 2.372367, 2.482318,
2.955525, 3.695009, 4.466863, 4.953736, 4.881621, 4.490706, 3.701351, 3.026894, 2.526035, 2.307822,
2.504045, 2.009562, 1.657256, 1.707543, 2.254479, 3.236273, 4.890536, 5.39631, 3.982771, 4.165687,
5.54563, 6.609555, 7.075383, 8.407475, 8.452162, 7.136439, 6.892845, 6.899497, 6.83426, 7.041435,
7.500181, 8.586868, 9.261867, 10.71992, 12.38344, 10.0349, 8.141942, 8.577694, 8.845512, 8.441437,
8.173477, 8.388666, 8.842992, 10.05801, 11.66855, 10.79198, 9.366837, 8.920071, 2.768534, 2.465336,
2.54276, 2.779685, 2.887887, 2.934226, 2.712695],

"RHOB": [2.531524, 2.542067, 2.551925, 2.55513, 2.557519, 2.558967, 2.561965, 2.556856,


2.541915, 2.540585, 2.543417, 2.551155, 2.556436, 2.558, 2.559624, 2.558896, 2.544479, 2.537069,
2.541875, 2.545977, 2.541851, 2.536336, 2.536139, 2.537093, 2.539953, 2.545588, 2.54862, 2.548865,
2.54932, 2.544922, 2.532604, 2.517425, 2.511097, 2.521466, 2.525083, 2.523863, 2.521806, 2.52041,
2.517826, 2.51254, 2.512666, 2.513387, 2.522799, 2.522401, 2.520155, 2.517012, 2.510036, 2.514996,
2.5137, 2.518203, 2.523189, 2.521506, 2.520132, 2.518902, 2.514719, 2.514928, 2.520892, 2.526369,
2.530068, 2.528176, 2.525935, 2.528389, 2.537182, 2.531653, 2.52806, 2.523903, 2.520168, 2.520361,
2.527799, 2.52648, 2.532638, 2.539931, 2.553304, 2.556603, 2.551496, 2.541516, 2.52083, 2.515224,
2.550452, 2.56288, 2.571036, 2.568226, 2.57287, 2.560672],

"PEF": [3.617409, 3.640286, 3.661446, 3.686015, 3.67083, 3.648049, 3.568604, 3.488262, 3.408547,
3.373072, 3.358348, 3.376372, 3.406852, 3.427814, 3.448457, 3.473017, 3.491247, 3.532272, 3.572902,
3.608074, 3.615924, 3.635189, 3.665405, 3.688682, 3.715249, 3.743406, 3.768141, 3.749162, 3.681363,
3.56331, 3.406662, 3.284232, 3.168859, 3.087751, 3.093779, 3.122155, 3.148562, 3.200313, 3.250091,
3.261484, 3.318861, 3.364056, 3.398093, 3.412377, 3.424822, 3.430919, 3.387086, 3.388278, 3.411442,
3.425616, 3.438851, 3.451566, 3.465326, 3.493689, 3.520285, 3.530327, 3.510839, 3.460394, 3.448885,
3.395862, 3.360478, 3.391446, 3.409838, 3.427821, 3.435013, 3.437298, 3.433494, 3.394591, 3.349494,
3.336358, 3.423594, 3.466463, 3.490405, 3.506466, 3.534566, 3.563658, 3.56308, 4.906909, 4.905381,
4.901607, 4.895643, 4.902998, 4.963295, 4.977894],

"Porosity": [0.280058, 0.281979, 0.283446, 0.28337, 0.282537, 0.281612, 0.282569, 0.281775,


0.282326, 0.288555, 0.282012, 0.275257, 0.271408, 0.269598, 0.270425, 0.29628, 0.354395, 0.387224,
0.378893, 0.377423, 0.377686, 0.382844, 0.385745, 0.395121, 0.398137, 0.387124, 0.354662, 0.298995,
0.239778, 0.209896, 0.216945, 0.225822, 0.229904, 0.236515, 0.252258, 0.270697, 0.276554, 0.274268,
0.268104, 0.256966, 0.263344, 0.264213, 0.256645, 0.248016, 0.240745, 0.234897, 0.235432, 0.242197,
0.247513, 0.24581, 0.234774, 0.223243, 0.219042, 0.220145, 0.22447, 0.229339, 0.232678, 0.235687,
0.238827, 0.243021, 0.235687, 0.225332, 0.22157, 0.220449, 0.220196, 0.221122, 0.222243, 0.223263,
0.258265, 0.228389, 0.23023, 0.228461, 0.223256, 0.208942, 0.198209, 0.200014, 0.205737, 0.205758,
0.203966, 0.201441, 0.20105, 0.195252, 0.192722, 0.19831]

df = pd.DataFrame(data)

# Step 2: Split the data into features (X) and target (y)

X = df.drop("Porosity", axis=1)

y = df["Porosity"]

# Step 3: Split the data into training and testing sets

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Step 4: Train the Random Forest model

rf_model = RandomForestRegressor(n_estimators=100, random_state=42)

rf_model.fit(X_train, y_train)
# Step 5: Test the model

y_pred = rf_model.predict(X_test)

# Step 6: Evaluate the model

mse = mean_squared_error(y_test, y_pred)

r2 = r2_score(y_test, y_pred)

print(f"Mean Squared Error (MSE): {mse}")

print(f"R² Score: {r2}")

# Step 7: Plot actual vs predicted porosity

plt.figure(figsize=(8, 6))

plt.scatter(y_test, y_pred, color='blue', label='Actual vs Predicted')

plt.plot([y_test.min(), y_test.max()], [y_test.min(), y_test.max()], 'k--', lw=2, label='Ideal Fit')

plt.xlabel('Actual Porosity')

plt.ylabel('Predicted Porosity')

plt.title('Actual vs Predicted Porosity')

plt.legend()

plt.show()

# Step 8: Display actual and predicted porosity in a table

results = pd.DataFrame({'Actual Porosity': y_test, 'Predicted Porosity': y_pred})

print(results)
Output

You might also like