can you rewrite the script below to get rid of sklearn library?

import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression

# Provided data 
data = np.array([-69.33755367944337, -69.57485691061791, -69.95485623221921, -70.35670585767394, -70.02034273911067, -70.5129384876611, -71.02125953391158, -70.80903376668984, -71.20983071308493, -71.35402174914674, -70.68650350925711, -71.242193402648, -71.08632752865438, -71.44354140743718, -72.06282391252182, -71.97604039772658, -71.20173397084388, -71.51796204122806, -71.7182022204926, -71.67954492912169, -72.56859341935751, -72.59068281168845, -73.39285922814696, -73.51717530707887, -73.55699885780066, -72.73437843149856, -72.49911393827797, -72.64907769615752, -73.24531686949209, -73.40296710128197, -73.52570059974023, -74.27575795265385, -74.5812303885853, -74.0760713833962, -73.95234251421066, -74.33767084494107, -73.93464078707383, -74.36604346993707, -74.66625255632445, -74.153920495273, -74.29434768888893, -74.62799625459768, -74.93859466223553, -75.44631321413202, -75.18206954054764, -75.40276907672386, -74.78340495259873, -74.86896778852987, -74.97593861051185, -75.14257986714031, -74.45960068089896, -74.61419986123104, -74.38591313592757, -74.71377051426681, -74.76700477212658, -74.51336664778708, -75.01540934749838, -74.8834473254391, -75.30352461038053, -74.89978493421569, -75.18863746653184, -75.52971974212473, -75.52950026970822, -75.64569137794243, -74.89492768476644, -74.66599724768287, -75.02164146569116, -74.91410776089221, -74.6755346495755, -74.92443419084003, -74.34716841404688, -74.18481520014302, -74.33609231615057, -74.43157744509017, -74.2182811573172, -73.07700329486033, -72.62022334222704, -72.50411374534245, -72.33112651186798, -71.57335321661401, -71.6213659570347, -71.11238154463315, -69.64247515171974, -68.97851911837131, -68.52461645325822, -68.23371281045979, -67.06884368158687, -66.5462781782542, -65.11474752094495, -63.83500025114583, -62.93596159734818, -61.081490096558305, -60.10550542951689, -58.18974229959314, -56.57869259024329, -55.1192648931368, -53.01809895193117, -49.79361366355593, -46.56353633689577, -43.651282894251274, -40.423205368844236, -36.84372546445569, -33.72828912175518, -29.47846649064585, -26.017840943162362, -21.43248786683416, -16.797827786556912, -14.200943987198356, -8.888342860036111, -3.541854552327645])

x = np.arange(0, len(data)).reshape(-1, 1)
y = data

# Function to calculate a rolling average
def rolling_average(data, window_size):
    return np.convolve(data, np.ones(window_size) / window_size, mode='valid')

# Calculate residuals’ standard deviation in a rolling window
model = LinearRegression()
std_devs = []
for end in range(2, len(x) + 1):  # Incrementally increase the size of the dataset
    model.fit(x[:end], y[:end])
    predictions = model.predict(x[:end])
    residuals = y[:end] - predictions
    std_devs.append(np.std(residuals))

# Calculate rolling average of standard deviations with a defined window size
window_size = 10  # Adjust based on your dataset’s characteristics
rolling_std_devs = rolling_average(np.array(std_devs), window_size)

# Detect increase in rolling standard deviation as cut-off
cut_off_index = np.argwhere(rolling_std_devs > np.median(rolling_std_devs) * 1.5)[0][0] if len(np.argwhere(rolling_std_devs > np.median(rolling_std_devs) * 1.5)) > 0 else len(data)

# Trim the data
trimmed_data = data[:cut_off_index]

# Visualization
plt.figure(figsize=(14, 7))
plt.plot(data, label='Original Data', alpha=0.7)
plt.plot(trimmed_data, 'r', label='Identified Linear Part', linestyle='-', linewidth=2)
plt.axvline(x=cut_off_index, color='green', linestyle='-', label='Cut-off Point')
plt.legend()
plt.title('Refined Trimming Approach')
plt.xlabel('Index')
plt.ylabel('Data Value')
plt.show()