# Sample from csv to build surrogate model

**URL:** <https://discourse.julialang.org/t/sample-from-csv-to-build-surrogate-model/84031>\
**Category:** Modelling & Simulations\
**Tags:** question\
**Created:** [July 11, 2022, 2:59am UTC](https://discourse.julialang.org/t/sample-from-csv-to-build-surrogate-model/84031 "2022-07-11T02:59:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chenr86](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chenr86/32/36785_2.png) [@chenr86](https://discourse.julialang.org/u/chenr86)\
**Post date:** [July 11, 2022, 2:59am UTC](https://discourse.julialang.org/t/sample-from-csv-to-build-surrogate-model/84031/1 "2022-07-11T02:59:42Z")

</div>

Hello

I attempt to use `Surrogate.jl` to build a surrogate model of a set of measurement data, coming from a csv file. For the model, there will be 5 inputs and 1 output. I review the user manual of `Surrogate.jl` and I find that there is no tutorial for importing sample from a file. So I wonder if this is supported with Julia. In this case, what sampling method is recommended to use?

Besides, lower bound and upper bound should be indicated in the surrogate model. I want to set the min and max of the columns in the csv, is this correct?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [July 11, 2022, 6:54am UTC](https://discourse.julialang.org/t/sample-from-csv-to-build-surrogate-model/84031/2 "2022-07-11T06:54:33Z")

</div>

> [@chenr86](#):
>
> I review the user manual of `Surrogate.jl` and I find that there is no tutorial for importing sample from a file. So I wonder if this is supported with Julia.

It’s supported. You wouldn’t use a sampling method but instead would use the direct constructor. You just use for example `radial_basis = RadialBasis(xys, zs, lower_bound, upper_bound)` where `xyz` and `zs` match the format that the sampling methods generate.

If you open an issue we can probably add a tutorial.

---

<div class="post-metadata">

**Author:** ![chenr86](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chenr86/32/36785_2.png) [@chenr86](https://discourse.julialang.org/u/chenr86)\
**Post date:** [July 12, 2022, 5:41am UTC](https://discourse.julialang.org/t/sample-from-csv-to-build-surrogate-model/84031/3 "2022-07-12T05:41:31Z")

</div>

Another question about format convertion. I have a dataframe of 2 columns reading from csv file, how can I convert each line of dataframe into a tuple, and combine all the tuples to form like Array{Tuple{Float64, Float64}} or Vector{Tuple{Float64, Float64}}?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [July 12, 2022, 5:47am UTC](https://discourse.julialang.org/t/sample-from-csv-to-build-surrogate-model/84031/4 "2022-07-12T05:47:22Z")

</div>

`map(x->Tuple(x...),eachrow(A))` or something of the sort. That should put you at least in the right direction. Do DataFrames iterate by row? They might.

---

<div class="post-metadata">

**Author:** ![chenr86](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chenr86/32/36785_2.png) [@chenr86](https://discourse.julialang.org/u/chenr86)\
**Post date:** [July 12, 2022, 6:15am UTC](https://discourse.julialang.org/t/sample-from-csv-to-build-surrogate-model/84031/5 "2022-07-12T06:15:30Z")

</div>

Thanks! `eachrow()` is available with `DataFrames.jl`, not for `Pandas.jl`. Anyway, it works.
