Загрузить файлы в «/»
This commit is contained in:
commit
8a1eba3aad
5 changed files with 296 additions and 0 deletions
24
data.json
Normal file
24
data.json
Normal file
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"store": {
|
||||
"item": [
|
||||
{
|
||||
"id": 0,
|
||||
"category": "ML_model",
|
||||
"title": "Titanic",
|
||||
"price": 400
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"category": "ML_model",
|
||||
"title": "Diabet",
|
||||
"price": 400
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"category": "Not_ML_Model",
|
||||
"title": "Punk_Rock",
|
||||
"price": 700
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
10
go.mod
Normal file
10
go.mod
Normal file
|
@ -0,0 +1,10 @@
|
|||
module store
|
||||
|
||||
go 1.21.6
|
||||
|
||||
require (
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20240112103746-ed7362810021
|
||||
github.com/sajari/regression v1.0.1
|
||||
)
|
||||
|
||||
require gonum.org/v1/gonum v0.14.0 // indirect
|
8
go.sum
Normal file
8
go.sum
Normal file
|
@ -0,0 +1,8 @@
|
|||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20240112103746-ed7362810021 h1:ojv5usqbh/Dxe67osTxjpA5mn51TxzyTOn7fbzBHdx0=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20240112103746-ed7362810021/go.mod h1:J/Mk6+nKeKSW4wygkZQFLQ6SkLOSGX5Ga0RuuuktEag=
|
||||
github.com/sajari/regression v1.0.1 h1:iTVc6ZACGCkoXC+8NdqH5tIreslDTT/bXxT6OmHR5PE=
|
||||
github.com/sajari/regression v1.0.1/go.mod h1:NeG/XTW1lYfGY7YV/Z0nYDV/RGh3wxwd1yW46835flM=
|
||||
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug=
|
||||
golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
|
||||
gonum.org/v1/gonum v0.14.0 h1:2NiG67LD1tEH0D7kM+ps2V+fXmsAnpUeec7n8tcr4S0=
|
||||
gonum.org/v1/gonum v0.14.0/go.mod h1:AoWeoz0becf9QMWtE8iWXNXc27fK4fNeHNf/oMejGfU=
|
249
store.go
Normal file
249
store.go
Normal file
|
@ -0,0 +1,249 @@
|
|||
package store
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/std"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
balance int
|
||||
titanic int
|
||||
diabetes int
|
||||
punk_rock []string
|
||||
}
|
||||
|
||||
const storeURLKey = "storeURL"
|
||||
|
||||
func _deploy(data interface{}, isUpdate bool) {
|
||||
if isUpdate {
|
||||
return
|
||||
}
|
||||
|
||||
ctx := storage.GetContext()
|
||||
storeURL := ""
|
||||
storage.Put(ctx, storeURLKey, storeURL)
|
||||
}
|
||||
|
||||
func NewUser(name string) {
|
||||
ctx := storage.GetContext()
|
||||
|
||||
existingUser := storage.Get(ctx, name)
|
||||
if existingUser != nil {
|
||||
panic("user already exists")
|
||||
}
|
||||
|
||||
punk_rock := make([]string, 0)
|
||||
|
||||
user := User{
|
||||
balance: 1000,
|
||||
titanic: -1,
|
||||
diabetes: -1,
|
||||
punk_rock: punk_rock,
|
||||
}
|
||||
storage.Put(ctx, name, std.Serialize(user))
|
||||
}
|
||||
|
||||
func getUser(name string) User {
|
||||
ctx := storage.GetReadOnlyContext()
|
||||
data := storage.Get(ctx, name)
|
||||
if data == nil {
|
||||
panic("user not found")
|
||||
}
|
||||
|
||||
return std.Deserialize(data.([]byte)).(User)
|
||||
}
|
||||
|
||||
func Balance(name string) int {
|
||||
u := getUser(name)
|
||||
return u.balance
|
||||
}
|
||||
|
||||
func Titanic(name string) int {
|
||||
u := getUser(name)
|
||||
return u.titanic
|
||||
}
|
||||
|
||||
func Diabetes(name string) int {
|
||||
u := getUser(name)
|
||||
return u.diabetes
|
||||
}
|
||||
|
||||
func Punk_rock(name string) []string {
|
||||
u := getUser(name)
|
||||
return u.punk_rock
|
||||
}
|
||||
|
||||
func DiabetesModel(name string, age int, sex int, w int, h int) {
|
||||
|
||||
h = h / 100
|
||||
var bmi int = w / (h * h)
|
||||
user := getUser(name)
|
||||
|
||||
//Predicted = 152.1335 + age*138.9039 + sex*-36.1353 + bmi*926.9120
|
||||
var predicted = (1521335 + age*1389039 + sex*-361353 + bmi*9269120) / 100
|
||||
|
||||
user.diabetes = predicted
|
||||
user.balance -= 400
|
||||
|
||||
ctx := storage.GetContext()
|
||||
storage.Put(ctx, name, std.Serialize(user))
|
||||
|
||||
/*
|
||||
f, err := os.Open("diabetes.csv")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
reader := csv.NewReader(f)
|
||||
|
||||
reader.FieldsPerRecord = -1
|
||||
trainingData, err := reader.ReadAll()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var r regression.Regression
|
||||
r.SetObserved("y")
|
||||
r.SetVar(0, "age")
|
||||
r.SetVar(1, "sex")
|
||||
r.SetVar(2, "bmi")
|
||||
|
||||
for i, record := range trainingData {
|
||||
|
||||
if i == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
yVal, err := strconv.ParseFloat(record[10], 64)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
ageVal, err := strconv.ParseFloat(record[0], 64)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
sexVal, err := strconv.ParseFloat(record[1], 64)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
bmiVal, err := strconv.ParseFloat(record[2], 64)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
r.Train(regression.DataPoint(yVal, []float64{ageVal, sexVal, bmiVal}))
|
||||
}
|
||||
r.Run()
|
||||
Predicted, err := r.Predict([]float64{age, sex, bmi})
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
func TitanicModel(name string, age int, sibSp int, parch int, embarked int, sex int, pclass int) {
|
||||
user := getUser(name)
|
||||
|
||||
//Predicted = 0.9438 + Age*-0.0065 + SibSp*-0.0507 + Parch*-0.0081 + Embarked*-0.0320 + Sex*0.4848 + Pclass*-0.1973
|
||||
var predicted = (9438 + age*-65 + sibSp*-507 + parch*-81 + embarked*-320 + sex*4848 + pclass*-1973) / 100
|
||||
|
||||
user.titanic = predicted
|
||||
user.balance -= 400
|
||||
ctx := storage.GetContext()
|
||||
storage.Put(ctx, name, std.Serialize(user))
|
||||
/*
|
||||
f, err := os.Open("titanic_numeric.csv")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
reader := csv.NewReader(f)
|
||||
|
||||
reader.FieldsPerRecord = 7
|
||||
trainingData, err := reader.ReadAll()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
var r regression.Regression
|
||||
r.SetObserved("Survived")
|
||||
r.SetVar(0, "Age")
|
||||
r.SetVar(1, "SibSp")
|
||||
r.SetVar(2, "Parch")
|
||||
r.SetVar(3, "Embarked")
|
||||
r.SetVar(4, "Sex")
|
||||
r.SetVar(5, "Pclass")
|
||||
|
||||
for i, record := range trainingData {
|
||||
|
||||
if i == 0 {
|
||||
continue
|
||||
}
|
||||
survivedVal, err := strconv.ParseFloat(record[6], 64)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
ageVal, err := strconv.ParseFloat(record[0], 64)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
sibSpVal, err := strconv.ParseFloat(record[1], 64)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
parchVal, err := strconv.ParseFloat(record[2], 64)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
embarkedVal, err := strconv.ParseFloat(record[3], 64)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
sexVal, err := strconv.ParseFloat(record[4], 64)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
pclassVal, err := strconv.ParseFloat(record[5], 64)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
r.Train(regression.DataPoint(survivedVal, []float64{ageVal, sibSpVal, parchVal, embarkedVal, sexVal, pclassVal}))
|
||||
}
|
||||
|
||||
r.Run()
|
||||
predicted, err := r.Predict([]float64{age, sibSp, parch, embarked, sex, pclass})
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
func Punk_Rock(name string, group string) {
|
||||
user := getUser(name)
|
||||
|
||||
punkRockGroups := []string{"Йорш", "Элизиум", "Бригадный подряд", "Порнофильмы"}
|
||||
|
||||
for _, g := range punkRockGroups {
|
||||
if group == g {
|
||||
user.punk_rock = append(user.punk_rock, "good")
|
||||
} else {
|
||||
user.punk_rock = append(user.punk_rock, "hmm")
|
||||
}
|
||||
}
|
||||
user.balance -= 700
|
||||
ctx := storage.GetContext()
|
||||
storage.Put(ctx, name, std.Serialize(user))
|
||||
}
|
5
store.yml
Normal file
5
store.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
name: MLStore
|
||||
supportedstandards: []
|
||||
events:
|
||||
permissions:
|
||||
- methods: '*'
|
Loading…
Reference in a new issue