public IHttpActionResult PutwinequalityRed(int id, winequalityRed winequalityRed) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != winequalityRed.ID) { return(BadRequest()); } db.Entry(winequalityRed).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!winequalityRedExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetwinequalityRed(int id) { winequalityRed winequalityRed = db.winequalityRed.Find(id); if (winequalityRed == null) { return(NotFound()); } return(Ok(winequalityRed)); }
public IHttpActionResult PostwinequalityRed(winequalityRed winequalityRed) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.winequalityRed.Add(winequalityRed); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = winequalityRed.ID }, winequalityRed)); }
public IHttpActionResult DeletewinequalityRed(int id) { winequalityRed winequalityRed = db.winequalityRed.Find(id); if (winequalityRed == null) { return(NotFound()); } db.winequalityRed.Remove(winequalityRed); db.SaveChanges(); return(Ok(winequalityRed)); }
public Normalize(winequalityRed wine, decimal MAXfixedAcidity, decimal MAXvolatileAcidity, decimal MAXcitricAcid, decimal MAXresidualSugar, decimal MAXchlorides, decimal MAXfreeSulfurDioxide, decimal MAXtotalSulfurDioxide, decimal MAXdensity, decimal MAXpH, decimal MAXsulphates, decimal MAXalcohol, decimal MAXquality) { fixedAcidity = Convert.ToDecimal(wine.fixed_acidity, CultureInfo.InvariantCulture) / (decimal)MAXfixedAcidity; volatileAcidity = Convert.ToDecimal(wine.volatile_acidity, CultureInfo.InvariantCulture) / (decimal)MAXvolatileAcidity; citricAcid = Convert.ToDecimal(wine.citric_acid, CultureInfo.InvariantCulture) / (decimal)MAXcitricAcid; residualSugar = Convert.ToDecimal(wine.residual_sugar, CultureInfo.InvariantCulture) / (decimal)MAXresidualSugar; chlorides = Convert.ToDecimal(wine.chlorides, CultureInfo.InvariantCulture) / (decimal)MAXchlorides; freeSulfurDioxide = Convert.ToDecimal(wine.free_sulfur_dioxide, CultureInfo.InvariantCulture) / (decimal)MAXfreeSulfurDioxide; totalSulfurDioxide = Convert.ToDecimal(wine.total_sulfur_dioxide, CultureInfo.InvariantCulture) / (decimal)MAXtotalSulfurDioxide; density = Convert.ToDecimal(wine.density, CultureInfo.InvariantCulture) / (decimal)MAXdensity; pH = Convert.ToDecimal(wine.pH, CultureInfo.InvariantCulture) / (decimal)MAXpH; sulphates = Convert.ToDecimal(wine.sulphates, CultureInfo.InvariantCulture) / (decimal)MAXsulphates; alcohol = Convert.ToDecimal(wine.alcohol, CultureInfo.InvariantCulture) / (decimal)MAXalcohol; quality = Convert.ToDecimal(wine.quality, CultureInfo.InvariantCulture) / (decimal)MAXquality; }
public void setResponse(winequalityRed wine) { //normalize cus Normalize nWine = new Normalize(wine, MAXfixedAcidity, MAXvolatileAcidity, MAXcitricAcid, MAXresidualSugar, MAXchlorides, MAXfreeSulfurDioxide, MAXtotalSulfurDioxide, MAXdensity, MAXpH, MAXsulphates, MAXalcohol, MAXquality ); //calculate all distances for (int i = 0; i < this.totalTrainset; i++) { distances[i] = new Distance(); distances[i].distance = 0; distances[i].index = i; //normalize element Normalize tmp = new Normalize(this.trainset[i], MAXfixedAcidity, MAXvolatileAcidity, MAXcitricAcid, MAXresidualSugar, MAXchlorides, MAXfreeSulfurDioxide, MAXtotalSulfurDioxide, MAXdensity, MAXpH, MAXsulphates, MAXalcohol, MAXquality); //distance between two fixedAcidity normalized distances[i].distance = distances[i].distance + getDistance (Convert.ToDecimal(nWine.fixedAcidity, CultureInfo.InvariantCulture), Convert.ToDecimal(tmp.fixedAcidity, CultureInfo.InvariantCulture)); //distance between two volatileAcidity normalized distances[i].distance = distances[i].distance + getDistance (Convert.ToDecimal(nWine.volatileAcidity, CultureInfo.InvariantCulture), Convert.ToDecimal(tmp.volatileAcidity, CultureInfo.InvariantCulture)); //distance between two citricAcid normalized distances[i].distance = distances[i].distance + getDistance (Convert.ToDecimal(nWine.citricAcid, CultureInfo.InvariantCulture), Convert.ToDecimal(tmp.citricAcid, CultureInfo.InvariantCulture)); //distance between two residualSugar normalized distances[i].distance = distances[i].distance + getDistance (Convert.ToDecimal(nWine.residualSugar, CultureInfo.InvariantCulture), Convert.ToDecimal(tmp.residualSugar, CultureInfo.InvariantCulture)); //distance between two chlorides normalized distances[i].distance = distances[i].distance + getDistance (Convert.ToDecimal(nWine.chlorides, CultureInfo.InvariantCulture), Convert.ToDecimal(tmp.chlorides, CultureInfo.InvariantCulture)); //distance between two freeSulfurDioxide normalized distances[i].distance = distances[i].distance + getDistance (Convert.ToDecimal(nWine.freeSulfurDioxide, CultureInfo.InvariantCulture), Convert.ToDecimal(tmp.freeSulfurDioxide, CultureInfo.InvariantCulture)); //distance between two totalSulfurDioxide normalized distances[i].distance = distances[i].distance + getDistance (Convert.ToDecimal(nWine.totalSulfurDioxide, CultureInfo.InvariantCulture), Convert.ToDecimal(tmp.totalSulfurDioxide, CultureInfo.InvariantCulture)); //distance between two density normalized distances[i].distance = distances[i].distance + getDistance (Convert.ToDecimal(nWine.density, CultureInfo.InvariantCulture), Convert.ToDecimal(tmp.density, CultureInfo.InvariantCulture)); //distance between two pH normalized distances[i].distance = distances[i].distance + getDistance (Convert.ToDecimal(nWine.pH, CultureInfo.InvariantCulture), Convert.ToDecimal(tmp.pH, CultureInfo.InvariantCulture)); //distance between two sulphates normalized distances[i].distance = distances[i].distance + getDistance (Convert.ToDecimal(nWine.sulphates, CultureInfo.InvariantCulture), Convert.ToDecimal(tmp.sulphates, CultureInfo.InvariantCulture)); //distance between two alcohol normalized distances[i].distance = distances[i].distance + getDistance (Convert.ToDecimal(nWine.alcohol, CultureInfo.InvariantCulture), Convert.ToDecimal(tmp.alcohol, CultureInfo.InvariantCulture)); //distance between two quality normalized distances[i].distance = distances[i].distance + getDistance (Convert.ToDecimal(nWine.quality, CultureInfo.InvariantCulture), Convert.ToDecimal(tmp.quality, CultureInfo.InvariantCulture)); }// end loop //sort for (int i = 0; i < totalTrainset - 1; i++) { for (int j = i + 1; j < totalTrainset; j++) { if (distances[i].distance > distances[j].distance) { Distance tmp = distances[i]; distances[i] = distances[j]; distances[j] = tmp; } //swap } //end j loop } //end i loop //select k nearest neighbor int yesCount = 0; int noCount = 0; decimal sumQuality = 0; for (int i = 0; i < kNN; i++) { winequalityRed tmp = trainset[distances[i].index]; sumQuality += Convert.ToDecimal(tmp.quality, CultureInfo.InvariantCulture); //if (tmp.getResponse() == 0) //{ // noCount = noCount + 1; //} //else if ( tmp.getResponse() == 1 ) //{ // yesCount = yesCount + 1; //} } //set response value for unknown customer //if (yesCount > noCount) //{ // cus.setResponse(1); //} //else if (yesCount < noCount) //{ // cus.setResponse(0); //} wine.quality = ((int)Math.Round(sumQuality / (decimal)kNN)).ToString(); }