Skip to content

Commit

Permalink
Fixed RANSAC tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerAK committed Aug 8, 2024
1 parent 82a550a commit 5c0c157
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
4 changes: 2 additions & 2 deletions protzilla/data_analysis/time_series_regression_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def time_series_linear_regression(
X_group = group_df[["Time"]]
y_group = group_df["Intensity"]

X_train, X_test, y_train, y_test = train_test_split(X_group, y_group, test_size=train_size, shuffle=False)
X_train, X_test, y_train, y_test = train_test_split(X_group, y_group, train_size=train_size, shuffle=False)
model = LinearRegression()
model.fit(X_train, y_train)

Expand Down Expand Up @@ -314,7 +314,7 @@ def time_series_ransac_regression(
})

else:
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=train_size, shuffle=False)
X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=train_size, shuffle=False)
model = RANSACRegressor(base_estimator=LinearRegression())
model.fit(X_train, y_train)

Expand Down
54 changes: 45 additions & 9 deletions tests/protzilla/data_analysis/test_time_series_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def time_series_test_data():

def test_linear_regression_plot_with_grouping(show_figures, time_series_test_data):
test_intensity, test_metadata = time_series_test_data
outputs = time_series_linear_regression(test_intensity, test_metadata, "Protein1", 0.2,"With Grouping")
outputs = time_series_linear_regression(test_intensity, test_metadata, "Protein1", 0.8,"With Grouping")
assert "plots" in outputs
fig = outputs["plots"][0]
if show_figures:
Expand All @@ -72,29 +72,38 @@ def test_linear_regression_plot_with_grouping(show_figures, time_series_test_dat

def test_linear_regression_plot_without_grouping(show_figures, time_series_test_data):
test_intensity, test_metadata = time_series_test_data
outputs = time_series_linear_regression(test_intensity, test_metadata, "Protein1", 0.2,"Without Grouping")
outputs = time_series_linear_regression(test_intensity, test_metadata, "Protein1", 0.8,"Without Grouping")
assert "plots" in outputs
fig = outputs["plots"][0]
if show_figures:
fig.show()
return

def test_linear_regression_plot_invalid_test_size(time_series_test_data):
def test_linear_regression_plot_invalid_train_size(time_series_test_data):
test_intensity, test_metadata = time_series_test_data
with pytest.raises(ValueError):
time_series_linear_regression(test_intensity, test_metadata, "Protein1", 2, "Without Grouping")
return

def test_linear_regression_outputs(time_series_test_data):
test_intensity, test_metadata = time_series_test_data
outputs = time_series_linear_regression(test_intensity, test_metadata, "Protein1", 0.2, "Without Grouping")
outputs = time_series_linear_regression(test_intensity, test_metadata, "Protein1", 0.8, "Without Grouping")
assert "scores" in outputs
return


def test_ransac_regression_plot_with_grouping(show_figures, time_series_test_data):
test_intensity, test_metadata = time_series_test_data
outputs = time_series_ransac_regression(test_intensity, test_metadata, "Protein1", 0.2, "With Grouping")
outputs = time_series_ransac_regression(
test_intensity,
test_metadata,
"Protein1",
100,
0.99,
"absolute_error",
0.8,
"With Grouping"
)
assert "plots" in outputs
fig = outputs["plots"][0]
if show_figures:
Expand All @@ -103,22 +112,49 @@ def test_ransac_regression_plot_with_grouping(show_figures, time_series_test_dat

def test_ransac_regression_plot_without_grouping(show_figures, time_series_test_data):
test_intensity, test_metadata = time_series_test_data
outputs = time_series_ransac_regression(test_intensity, test_metadata, "Protein1", 0.2, "Without Grouping")
outputs = time_series_ransac_regression(
test_intensity,
test_metadata,
"Protein1",
100,
0.99,
"absolute_error",
0.8,
"With Grouping"
)
assert "plots" in outputs
fig = outputs["plots"][0]
if show_figures:
fig.show()
return

def test_ransac_plot_invalid_test_size(time_series_test_data):
def test_ransac_plot_invalid_train_size(time_series_test_data):
test_intensity, test_metadata = time_series_test_data
with pytest.raises(ValueError):
time_series_ransac_regression(test_intensity, test_metadata, "Protein1", 2, "Without Grouping")
time_series_ransac_regression(
test_intensity,
test_metadata,
"Protein1",
100,
0.99,
"absolute_error",
2,
"With Grouping"
)
return

def test_ransac_regression_outputs(time_series_test_data):
test_intensity, test_metadata = time_series_test_data
outputs = time_series_ransac_regression(test_intensity, test_metadata, "Protein1", 0.2, "Without Grouping")
outputs = time_series_ransac_regression(
test_intensity,
test_metadata,
"Protein1",
100,
0.99,
"absolute_error",
0.8,
"With Grouping"
)
assert "scores" in outputs
return

Expand Down

0 comments on commit 5c0c157

Please sign in to comment.