|
|
|
|
|
by plg
2511 days ago
|
|
Something I always try with new (to me) languages: write a short script to (1) load a .txt file containing space-delimited columns of data; (2) fit a linear model in which one column is predicted by a linear combination of the others; (3) plot the predicted values again the actual values using dots and overlay a y=x line Tried this with Julia a short while ago and basically gave up, couldn’t figure out how to get something to plot. Has the Julia-verse changed? Is it easier now? I can do this in MATLAB in basically 3 or 4 lines of code. Python, not much more than that. |
|
``` using GLM, CSV, Plots
data = CSV.read("data.csv", header=["x","y"], types=[Float64, Float64]) #returns dataframe
ols = lm(@formula(y ~ x), data)
ypred = predict(ols)
yall = Base.hcat(data.y, ypred)
plot(data.x, yall, linewidth=2, title="Linear regression", label=["y", "ypred"], xlabel="x", ylabel="y")
```